]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): provide compat fallback for idle callback hydration strategy (#11935)
authorMichael Brevard <yonshi29@gmail.com>
Fri, 11 Oct 2024 03:22:01 +0000 (06:22 +0300)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 03:22:01 +0000 (11:22 +0800)
packages/runtime-core/src/hydrationStrategies.ts

index bb98ea93c208822af19977aa035a3f0147b477ca..bad39884830ea2d262464ca2f56bdc87289fa8ee 100644 (file)
@@ -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.