-
Notifications
You must be signed in to change notification settings - Fork 476
Fix noscript style evaluation during navigation (#1464) #1475
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
base: main
Are you sure you want to change the base?
Fix noscript style evaluation during navigation (#1464) #1475
Conversation
Prevent Turbo from evaluating <style> tags inside <noscript> elements during page rendering and snapshot creation by converting innerHTML to textContent. This fixes an issue where noscript styles would incorrectly be applied during navigation, potentially hiding page content.
Note on CI FailureThe CI failure appears to be from a pre-existing flaky test, not related to this PR's changes. The flaky test: I tested this on The noscript fix itself is working correctly and the new test coverage is stable. Happy to re-run CI or provide more details if needed! |
packagethief
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yujiteshima. This looks good. Just one (possibly silly) question. If turbo is controlling navigation we know that JavaScript is enabled, so any <noscript> element is irrelevant anyway. Instead of converting the element contents to text, could we just remove the element?
removeNoscriptElements() {
for (const noscriptElement of this.newElement.querySelectorAll("noscript")) {
noscriptElement.remove()
}
}|
@packagethief Thank you for the suggestion—not silly at all! I agree that removing Since Turbo is running, JavaScript is demonstrably enabled, making I'll update the implementation to use |
Since Turbo controls navigation only when JavaScript is enabled, noscript elements are unnecessary and can be removed entirely instead of converting their content to text. This approach keeps the DOM cleaner and better aligns with Turbo's progressive enhancement philosophy.
Since Turbo controls navigation only when JavaScript is enabled, noscript elements are unnecessary and can be removed entirely. The removal happens after document.adoptNode() to ensure consistent behavior across browsers, particularly Firefox.
|
@packagethief Updated! The implementation now removes The removal happens after All tests are passing on both Chrome and Firefox. |
Pull Request
Title: Fix noscript style evaluation during navigation
Summary
Fixes #1464
This PR prevents Turbo from incorrectly evaluating
<style>tags nested within<noscript>elements during page navigation.Problem
Turbo's page rendering mechanism was evaluating content inside
<noscript>elements, causing:display: nonestyles were applied during navigationSolution
The fix deactivates
<noscript>elements by converting theirinnerHTMLtotextContentin two critical places:page_renderer.js): Before adopting the new body elementpage_snapshot.js): When creating cached snapshotsThis conversion prevents browsers from parsing nested HTML/CSS while preserving the content as plain text.
Testing
Added a new test case that verifies styles inside
<noscript>elements are not evaluated during Turbo navigation.Reproduction Projects