Skip to content
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

feat!: universal head injection, drop activeHead #231

Merged
merged 6 commits into from
Sep 14, 2023

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Sep 14, 2023

πŸ”— Linked issue

❓ 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

This change drops the use of the implicit shared context provided by the activeHead export. Now we explicitly have the user opt-in to a shared head instance or they need to provide their own function to resolve the context.

⚠️ Breaking Changes

  • Removes the import getActiveHead(), instead you should use injectHead().
  • Does not automatically set a global head instance for servers, you will need to apply the context manually.

If you're not processing requests in parallel (such as a testing environment) then doing something like this is safe

const head = createSharedHead()

// just works - will leak in a server environment across parallel requests
useHead({ title: 'hello world' })

Otherwise, you will need to attach the head to a context and use that. For example, in Nuxt we do the below. The useNuxtApp() context is provided with unctx.

setHeadInjectionHandler(() => useNuxtApp().vueApp._context.provides.usehead)

Note: It's important not to pass in a reference to a context within this function unless you're share it will be unique accross requests.

// bad
const nuxtApp = useNuxtApp() // context will leak across requests
setHeadInjectionHandler(() => nuxtApp.vueApp._context.provides.usehead)

πŸ“ Checklist

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

@vercel
Copy link

vercel bot commented Sep 14, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
unjs-unhead βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Sep 14, 2023 5:10pm

@harlan-zw harlan-zw changed the base branch from main to v2-major September 14, 2023 16:59
@harlan-zw harlan-zw merged commit 697aed4 into v2-major Sep 14, 2023
2 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.

1 participant