perf(nuxt): prevent head dom from rendering twice (#22974)

This commit is contained in:
Harlan Wilton 2023-09-04 10:12:56 +02:00 committed by GitHub
parent 4e05650cde
commit 421cab1adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -26,7 +26,10 @@ export default defineNuxtPlugin({
head.hooks.hook('dom:beforeRender', (context) => { context.shouldRender = !pauseDOMUpdates })
nuxtApp.hooks.hook('page:start', () => { pauseDOMUpdates = true })
// wait for new page before unpausing dom updates (triggered after suspense resolved)
nuxtApp.hooks.hook('page:finish', syncHead)
nuxtApp.hooks.hook('page:finish', () => {
// app:suspense:resolve hook will unpause the DOM
if (!nuxtApp.isHydrating) { syncHead() }
})
// unpause on error
nuxtApp.hooks.hook('app:error', syncHead)
// unpause the DOM once the mount suspense is resolved