javascript added using useHead is being executed on the server
I have a javascript to be executed on the client to check the browser version and also if some functionalities are available and if not match the criteria we redirect the user to a dedicated page (informing the user that he needs to update the browser)
But I see that the code added to the script tag is being executed on the server and being changed
original:
then turns into:
How can I prevent/fix this?
Thanks
16 Replies
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
thanks @Igor Jacaúna
I'll gonna take a look and see if it feets on my needs
even so, I'm trying to understand why the js code inside the script tag that is injected into the markup is being executed on the server and also changed
It's something that I wasn't expecting to happen as it should "just" inject it into the markup
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
I am not sure if it has to do with the way I'm declaring the js function
I'm creating it as a "string"
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
the code is inside app.vue
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
it's hard as it's the config is very complex
The addBodyClass function is called inside the if (typeof window !== 'undefined') { base on other conditions
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
No problem
now I'm confused
In my example, I have the same way as I have on the project and also doesn't change the code :/
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
nope. I forgot to set the SSR
Now I'm also getting the js code changed
![No description](https://cdn.answeroverflow.com/1218241880253268008/image.png)
looks like someone already reported this behavior
https://github.com/nuxt/nuxt/issues/22559
GitHub
Unexpected substitutions in embedded scripts in useHead · Issue #22...
Environment Operating System: Linux Node Version: v16.20.0 Nuxt Version: 3.6.5 Nitro Version: 2.5.2 Package Manager: npm@9.4.2 Builder: vite User Config: - Runtime Modules: - Reproduction https://s...
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View