index.ts 860 B

123456789101112131415161718192021
  1. // Convenience function to load polyfills and return a promise when it's done.
  2. // If there are no polyfills, then this is just Promise.resolve() which means
  3. // it will execute in the same tick of the event loop (i.e. near-instant).
  4. import { loadIntlPolyfills } from './intl';
  5. function importExtraPolyfills() {
  6. return import(/* webpackChunkName: "extra_polyfills" */ './extra_polyfills');
  7. }
  8. export function loadPolyfills() {
  9. // Safari does not have requestIdleCallback.
  10. // This avoids shipping them all the polyfills.
  11. const needsExtraPolyfills = !window.requestIdleCallback;
  12. return Promise.all([
  13. loadIntlPolyfills(),
  14. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- those properties might not exist in old browsers, even if they are always here in types
  15. needsExtraPolyfills && importExtraPolyfills(),
  16. ]);
  17. }