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

Putting anything inside a <noscript> tag causes Turbo to duplicate all <script> tags into the <body> #668

Open
jclemans opened this issue Aug 20, 2024 · 2 comments

Comments

@jclemans
Copy link

I still haven't made sense of what is going on here, but I just discovered that the <noscript> content in my application.html.erb file was what was causing Turbo to duplicate all the script tags that are in the <head> into the <body>. This was causing Turbo to show the following warning every time I clicked on a navigation link to another page:

You are loading Turbo from a <script> element inside the <body> element. This is probably not what you meant to do!

Load your application’s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change.

For more information, see: https://turbo.hotwired.dev/handbook/building#working-with-script-elements

Inspecting the page markup shows that all my script tags were present in both the head and body. When I comment out or delete just the <noscript> tag content, this warning disappears and script tags remain only in the head element as they should. Inside the <noscript> tag I have just two elements, a Facebook <img> tracking pixel, and a Google Tag Manager <iframe>, however, this issue is reproducible just just adding something as simple as <noscript><img src="" /></noscript>.

Anyone have any idea what is going on here?

@seanpdoyle
Copy link
Contributor

Thank you for opening this issue and bringing attention to this behavior.

Could you download the content from the repository's bug_report_template.rb locally, change it to re-create the behavior, then share the output here?

@jclemans
Copy link
Author

Is there an easy way to get that bug report template to open the html in an actual browser window? The issue only causes a warning, so the test does pass, but I can't see if the warning is present or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants