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

This commit is contained in:
Michael Brevard 2024-10-11 06:22:01 +03:00 committed by GitHub
parent 05685a9d7c
commit 1ae545a378
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View 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.