瀏覽代碼

fix(hydration): provide compat fallback for idle callback hydration strategy (#11935)

Michael Brevard 1 年之前
父節點
當前提交
1ae545a378
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      packages/runtime-core/src/hydrationStrategies.ts

+ 8 - 1
packages/runtime-core/src/hydrationStrategies.ts

@@ -1,6 +1,13 @@
-import { isString } from '@vue/shared'
+import { getGlobalThis, isString } from '@vue/shared'
 import { DOMNodeTypes, isComment } from './hydration'
 
+// Polyfills for Safari support
+// see https://caniuse.com/requestidlecallback
+const requestIdleCallback: Window['requestIdleCallback'] =
+  getGlobalThis().requestIdleCallback || (cb => setTimeout(cb, 1))
+const cancelIdleCallback: Window['cancelIdleCallback'] =
+  getGlobalThis().cancelIdleCallback || (id => clearTimeout(id))
+
 /**
  * A lazy hydration strategy for async components.
  * @param hydrate - call this to perform the actual hydration.