Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): add requestidlecallback polyfill for safari (#5231)

EYHNdf439877bd1b
diff --git a/packages/frontend/core/src/index.tsx b/packages/frontend/core/src/index.tsx
index 3667442d56..b7cef0c072 100644
--- a/packages/frontend/core/src/index.tsx
+++ b/packages/frontend/core/src/index.tsx
@@ -1,5 +1,6 @@
import './polyfill/ses-lockdown';
import './polyfill/intl-segmenter';
+import './polyfill/request-idle-callback';
import { WorkspaceFallback } from '@affine/component/workspace';
import { assertExists } from '@blocksuite/global/utils';
diff --git a/packages/frontend/core/src/polyfill/request-idle-callback.ts b/packages/frontend/core/src/polyfill/request-idle-callback.ts
new file mode 100644
index 0000000000..e3156d20df
--- /dev/null
+++ b/packages/frontend/core/src/polyfill/request-idle-callback.ts
@@ -0,0 +1,19 @@
+window.requestIdleCallback =
+ window.requestIdleCallback ||
+ function (cb) {
+ const 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);
+ };