-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
useHead
does not inject styles in concurrent pre-rendering
#22763
Comments
Start a new pull request in StackBlitz Codeflow. |
Possibly related to context, this may be a work-around if that's the case. Will test it properly tomorrow. export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.runWithContext(() => {
useHead({
style: [
{
innerHTML: ':root { --header-height: 5em; }',
tagPriority: -2,
id: 'nuxt-usehead-concurrency-bug',
},
],
});
})
}); |
Workaround const head = nuxtApp.vueApp._context.provides.usehead
head.push({
style: [
{
innerHTML: ':root { --header-height: 5em; }',
tagPriority: -2,
id: 'nuxt-usehead-concurrency-bug',
},
],
}) In Nuxt 3.7.we can also access the head from the ssrContext which is slightly nicer (for server plugins). export default defineNuxtPlugin((nuxtApp) => {
const head = nuxtApp.ssrContext!.head
head.push({
style: [
{
innerHTML: ':root { --header-height: 5em; }',
tagPriority: -2,
id: 'nuxt-usehead-concurrency-bug',
},
],
})
}); |
Seems to be an issue with the useHead context being unsynced with the nuxt app head instance. This would stem from an initial flaw in how I set up the global context for SSR, currently, there's a single export of Dropping I'm not sure what the best solution so any ideas would be helpful. |
Maybe related nuxt-modules/turnstile#271 |
The workaround works @harlan-zw Thank you for your fast investigation ❤️ |
This is now seems to be fixed in Unhead 1.4.0 without any workarounds. |
unhead is v1.4.1 |
Can you provide some reproduction details @Ni55aN |
https://github.com/retejs/retejs.org/tree/nuxt-use-head-issue after If I downgrade nuxt to 3.5, it works correctly |
Can you provide some actual code? I can't see what you mean, it looks like the examples don't have meta tags? I'd recommend upgrading using |
@harlan-zw it has latest nuxt version 3.7.0, right?
they have, but these tags are mixed up between different examples (in .output/public)
If I downgrade nuxt to 3.5, the resulting |
Please try out 3.7.1 🙏 |
@harlan-zw unfortunately after updating to 3.7.1 the I found a possible reason of the error (using UPD: An error is thrown when |
Would it be possible to make a separate issue @Ni55aN? It seems unrelated to the original |
Environment
Reproduction
https://stackblitz.com/edit/github-4ah2ty?file=app.vue,nuxt.config.ts
Describe the bug
We found an issue with
useHead
used in a plugin and usingnuxt generate
.Download the Stackblitz because they don't have the
grep
command.First, run
npm run generate
, it should generate 100 pages.Running:
Shows:
Then run:
Returns:
Happy to take a look at it @harlan-zw, seems related directly to
unhead
.Additional context
If I set the
concurrency
to1
, it works perfectly:But as you know this is not the best case.
Logs
No response
The text was updated successfully, but these errors were encountered: