Core: Add polyfill for fetch (#7401)

Core: Add polyfill for fetch
This commit is contained in:
Michael Shilman 2019-08-07 10:52:27 +08:00 committed by GitHub
commit 61ff1a70f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 2 deletions

View File

@ -82,6 +82,7 @@
"shelljs": "^0.8.3",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.4",
"unfetch": "^4.1.0",
"url-loader": "^2.0.1",
"util-deprecate": "^1.0.2",
"webpack": "^4.33.0",

View File

@ -0,0 +1,17 @@
import { window } from 'global';
export const importPolyfills = () => {
const polyfills = [];
if (!window.fetch) {
// manually patch window.fetch;
// see issue: <https://github.com/developit/unfetch/issues/101#issuecomment-454451035>
const patch = ({ default: fetch }) => {
window.fetch = fetch;
};
polyfills.push(import('unfetch/dist/unfetch').then(patch));
}
return Promise.all(polyfills);
};

View File

@ -1,6 +1,9 @@
import { document } from 'global';
import renderStorybookUI from '@storybook/ui';
import Provider from './provider';
import { importPolyfills } from './conditional-polyfills';
const rootEl = document.getElementById('root');
renderStorybookUI(rootEl, new Provider());
importPolyfills().then(() => {
const rootEl = document.getElementById('root');
renderStorybookUI(rootEl, new Provider());
});

View File

@ -29105,6 +29105,11 @@ undertaker@^1.2.1:
object.reduce "^1.0.0"
undertaker-registry "^1.0.0"
unfetch@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.1.0.tgz#6ec2dd0de887e58a4dee83a050ded80ffc4137db"
integrity sha512-crP/n3eAPUJxZXM9T80/yv0YhkTEx2K1D3h7D1AJM6fzsWZrxdyRuLN0JH/dkZh1LNH8LxCnBzoPFCPbb2iGpg==
unherit@^1.0.4:
version "1.1.2"
resolved "https://registry.yarnpkg.com/unherit/-/unherit-1.1.2.tgz#14f1f397253ee4ec95cec167762e77df83678449"