fix: delayed hydration for network idle

This commit is contained in:
Michael Brevard 2024-06-02 23:40:37 +03:00 committed by GitHub
parent 28647ecb30
commit 66dd659821
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -72,7 +72,7 @@ export const createLazyNetworkClientPage = (componentLoader: Component) => {
const nuxt = useNuxtApp() const nuxt = useNuxtApp()
const instance = getCurrentInstance()! const instance = getCurrentInstance()!
let vnode: VNode | null = null let vnode: VNode | null = null
if (import.meta.client && nuxt.isHydrating && instance.vnode?.el) { if (nuxt.isHydrating && instance.vnode?.el) {
vnode = createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1) vnode = createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1)
} }
const isIdle = ref(false) const isIdle = ref(false)
@ -90,7 +90,7 @@ export const createLazyNetworkClientPage = (componentLoader: Component) => {
idleHandle = null idleHandle = null
} }
}) })
return () => isIdle.value ? h(componentLoader, attrs) : vnode return () => isIdle.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createVNode(createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1)) : null
}, },
}) })
} }