Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix: fix shims for web worker

Wenzhao Hue93722900d4c
diff --git a/packages/core/src/common/shims.ts b/packages/core/src/common/shims.ts
index ae75fdb6de..b5324af913 100644
--- a/packages/core/src/common/shims.ts
+++ b/packages/core/src/common/shims.ts
@@ -18,11 +18,13 @@ export function installShims() {
installRequestIdleCallback();
}
-const TIME_WINDOW = 50;
+const glob = typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : window;
function installRequestIdleCallback() {
- if (typeof window.requestIdleCallback !== 'function') {
- window.requestIdleCallback = function shimRIC(callback: Function) {
+ const TIME_WINDOW = 50;
+
+ if (typeof glob.requestIdleCallback !== 'function') {
+ glob.requestIdleCallback = function shimRIC(callback: Function) {
const start = Date.now();
return setTimeout(function rICCallback() {
const remaining = Math.max(0, TIME_WINDOW - (Date.now() - start));
@@ -36,8 +38,8 @@ function installRequestIdleCallback() {
};
}
- if (typeof window.cancelIdleCallback !== 'function') {
- window.cancelIdleCallback = function shimCancelRIC(id: number) {
+ if (typeof glob.cancelIdleCallback !== 'function') {
+ glob.cancelIdleCallback = function shimCancelRIC(id: number) {
clearTimeout(id);
};
}