Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(react): update unhead context on initial <Head> render #534

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 3 commits into from
Mar 28, 2025

Conversation

Narixius
Copy link
Contributor

@Narixius Narixius commented Mar 28, 2025

πŸ”— Linked issue

Resolves #532

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ 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

During <Head> component rendering, applyHeadChanges was conditionally called based on the isBrowser flag. Instead, we now leverage the initial value of useRef to apply changes to the Unhead context and update it later using useEffect. This approach improves SSR compatibility without relying on environment-specific variables (e.g. isBrowser) and ensures useHead/<Head> calls execute in the correct order.

The previous implementation (relying on isBrowser) did not respect the useHead/<Head> execution order.

@harlan-zw
Copy link
Collaborator

Oh thanks πŸ™Œ I was just reviewing the code to see if we could drop the isBrowser

@harlan-zw harlan-zw merged commit 24ee392 into unjs:main Mar 28, 2025
1 of 3 checks passed
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.

During React SSR, <Head> component doesn't update the unhead context
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.