diff --git a/web/app/provider.tsx b/web/app/provider.tsx index 12b6a09f8..dba975a63 100644 --- a/web/app/provider.tsx +++ b/web/app/provider.tsx @@ -12,6 +12,8 @@ import { SWR_CONFIG } from "@/constants/swr-config"; import { resolveGeneralTheme } from "@/helpers/theme.helper"; // nprogress import { AppProgressBar } from "@/lib/n-progress"; +// polyfills +import "@/lib/polyfills"; // mobx store provider import { StoreProvider } from "@/lib/store-context"; // wrappers diff --git a/web/core/lib/polyfills/index.ts b/web/core/lib/polyfills/index.ts new file mode 100644 index 000000000..20b3b476c --- /dev/null +++ b/web/core/lib/polyfills/index.ts @@ -0,0 +1 @@ +export * from "./requestIdleCallback"; diff --git a/web/core/lib/polyfills/requestIdleCallback.ts b/web/core/lib/polyfills/requestIdleCallback.ts new file mode 100644 index 000000000..76dd4c29e --- /dev/null +++ b/web/core/lib/polyfills/requestIdleCallback.ts @@ -0,0 +1,24 @@ +if (typeof window !== "undefined" && window) { + // Add request callback polyfill to browser incase it does not exist + window.requestIdleCallback = + window.requestIdleCallback ?? + function (cb) { + var start = Date.now(); + return setTimeout(function () { + cb({ + didTimeout: false, + timeRemaining: function () { + return Math.max(0, 50 - (Date.now() - start)); + }, + }); + }, 1); + }; + + window.cancelIdleCallback = + window.cancelIdleCallback ?? + function (id) { + clearTimeout(id); + }; +} + +export {};