mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 02:44:51 +00:00
14 lines
391 B
TypeScript
14 lines
391 B
TypeScript
import { useNuxtApp } from '../nuxt'
|
|
import { requestIdleCallback } from '../compat/idle-callback'
|
|
|
|
export const onNuxtReady = (callback: () => any) => {
|
|
if (process.server) { return }
|
|
|
|
const nuxtApp = useNuxtApp()
|
|
if (nuxtApp.isHydrating) {
|
|
nuxtApp.hooks.hookOnce('app:suspense:resolve', () => { requestIdleCallback(callback) })
|
|
} else {
|
|
requestIdleCallback(callback)
|
|
}
|
|
}
|