mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 19:37:18 +00:00
15 lines
431 B
TypeScript
15 lines
431 B
TypeScript
import { useNuxtApp } from '../nuxt'
|
|
import { requestIdleCallback } from '../compat/idle-callback'
|
|
|
|
/** @since 3.1.0 */
|
|
export const onNuxtReady = (callback: () => any) => {
|
|
if (import.meta.server) { return }
|
|
|
|
const nuxtApp = useNuxtApp()
|
|
if (nuxtApp.isHydrating) {
|
|
nuxtApp.hooks.hookOnce('app:suspense:resolve', () => { requestIdleCallback(() => callback()) })
|
|
} else {
|
|
requestIdleCallback(() => callback())
|
|
}
|
|
}
|