8000 fix(nuxt): trigger immediate DOM update on `page:finish` by harlan-zw Β· Pull Request #22566 Β· nuxt/nuxt Β· GitHub
[go: up one dir, main page]

Skip to content

fix(nuxt): trigger immediate DOM update on page:finish #22566

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

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

harlan-zw
Copy link
Contributor

πŸ”— Linked issue

#22334, #22560

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When updating the DOM from head changes, we batch the changes, this reduces DOM thrashing. We use this batching when the page is finishing which is causing the linked issue.

However, we can just update the head immediately.

One issue with this solution though is the page:finish is now delayed, on average this is ~10ms for a few DOM updates (if needed), so maybe worth considering if this change is worth it.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@harlan-zw harlan-zw changed the title fix(head): trigger dom on page:finish immediately fix(head): trigger immediate DOM update on page:finish Aug 9, 2023
@harlan-zw harlan-zw changed the title fix(head): trigger immediate DOM update on page:finish fix(nuxt): trigger immediate DOM update on page:finish Aug 9, 2023
}
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', unpauseDom)
nuxtApp.hooks.hook('page:finish', syncHead)
Copy link
Member

Choose a reason for hiding this comment

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

What do you think? Would it make sense to dispatch the event but not await it?

Suggested change
nuxtApp.hooks.hook('page:finish', syncHead)
nuxtApp.hooks.hook('page:finish', () => { syncHead() })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we'd do this but then it doesn't solve the issues linked πŸ€”

There's an experimental flag we can enable that should make the initial SSR hydration 0ms to overcome this overhead.

The risk I see outside of that is if someone has a promise on one of the head tags that is extra slow to resolve it would slow the page transition. Although maybe that's useful for the title (as outlined in the issue)

@danielroe danielroe merged commit 89ad88b into main Aug 11, 2023
@danielroe danielroe deleted the fix/render-head-immediately-on-page-finish branch August 11, 2023 10:24
@github-actions github-actions bot mentioned this pull request Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0