Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 13 commits into from
Oct 11, 2024
17 changes: 16 additions & 1 deletion packages/runtime-core/src/hydrationStrategies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { isString } from '@vue/shared'
import { getGlobalThis, isString } from '@vue/shared'
import { DOMNodeTypes, isComment } from './hydration'

// https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/compat/idle-callback.ts
// Polyfills for Safari support
// https://caniuse.com/requestidlecallback
const requestIdleCallback: typeof getGlobalThis().requestIdleCallback =
getGlobalThis().requestIdleCallback ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be like this ReturnType<typeof getGlobalThis>['requestIdleCallback'] ?

(cb => {
return setTimeout(cb, 1)
})

const cancelIdleCallback: typeof getGlobalThis().cancelIdleCallback =
getGlobalThis().cancelIdleCallback ||
(id => {
clearTimeout(id)
})

/**
* A lazy hydration strategy for async components.
* @param hydrate - call this to perform the actual hydration.
Expand Down
Loading