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
inject <script>
in rendered HTML when ssr: false
#14172
Comments
<script>
in rendered HTML when ssr: false
It looks like to be caused by adding the meta in a plugin. https://github.com/nuxt/framework/tree/main/packages/nuxt/src/head I want to try to fix it, I think you could fix it by moving the adding of the meta to the module instead of the plugin. should I just check if it's not a ssr build and then just push it to the html? |
This comment was marked as outdated.
This comment was marked as outdated.
Using the new // server/plugins/render.ts
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('render:html', (html, { event }) => {
html.head.push('<script src="/config.js"></script>');
});
}) |
@pi0 Shall we close this then? |
Let's keep it open until introduce tag utils for a complete solution for nuxt/framework#5553. |
This was implemented in nuxt/framework#8975. |
Environment
Nuxt project info: 11:29:52
Darwin
v14.18.1
3.0.0-rc.1
npm@6.14.15
vite
typescript
,modules
,ssr
,app
,css
,vite
@pinia/nuxt@0.1.9
-
Reproduction
https://stackblitz.com/edit/github-ztv7ch-3v2mxy?file=nuxt.config.ts
Describe the bug
As described here: https://github.com/nuxt/framework/discussions/5476. I need to inject a script in the
<head>
tag, to be able to set some runtime configuration on the globalwindow
object.I'm injecting the script using the
nuxt.config.ts
:config.js
:The new meta module injects this script at runtime (as you can see, there is no
<script>
tag in the html output):The problem is that this script should be executed before anything else. But as you can see in the repro project, if I'm trying to access
window.config
in a Plugin, I getundefined
.This is because some of the application code is run before the
config.js
script is injected in the<head>
.There should be a way to run this script before anything else in the page.
Note: This issue is related to "client side only" projects (
ssr: false
), settingssr: true
solves this issue.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: