-
Notifications
You must be signed in to change notification settings - Fork 355
/
injectConditionalPolyfills.tsx
42 lines (38 loc) · 1.13 KB
/
injectConditionalPolyfills.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getBrowserInfo } from "../lib/browserInfo";
import polyfillCSSVars from "./polyfillCSSVars";
export default async function injectConditionalPolyfills() {
const browser = getBrowserInfo();
const pending: Promise<any>[] = [];
// Polyfill Intl.
let intlPromise = Promise.resolve();
if (!browser.supports.intl) {
intlPromise = (async () => {
const IntlPolyfill = (await import("intl")).default;
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
return;
})();
}
pending.push(
intlPromise.then(() => {
if (!browser.supports.intlPluralRules) {
return import("fluent-intl-polyfill");
}
return;
})
);
// Polyfill Intersection Observer.
if (!browser.supports.intersectionObserver) {
pending.push(import("intersection-observer"));
}
if (!browser.supports.proxyObject) {
pending.push(import("proxy-polyfill"));
}
if (!browser.supports.fetch) {
pending.push(import("whatwg-fetch"));
}
if (!browser.supports.cssVariables) {
pending.push(polyfillCSSVars());
}
await Promise.all(pending);
}