hotwired/turbo-rails

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

Opened this issue · 2 comments

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?

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?

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.