Skip to content

iAPI Router: Ignores <noscript> elements while preparing DOM. #70905

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

Merged
merged 7 commits into from
Jul 31, 2025

Conversation

vipul0425
Copy link
Contributor

What?

Closes #70876

Why?

The <style> or elements inside sections were handled as if they were placed outside and applied to the page after client-side navigation, which is not correct.

How?

This PR removes <noscript> elements during DOM preparation when extracting router regions and related resources, since the router only functions with JavaScript enabled. This prevents browsers and our style scripts from incorrectly extracting styles from those tags.

Testing Instructions

  1. Add a block of HTML in a template with a Query Loop block, with a element and a <style> tag that changes the body background within. E.g.:

    <noscript><style>body{ background: red !important; }</style></noscript>
  2. Ensure "force page reload" is disabled in the Query Loop block.

  3. Visit a page with the modified template.

  4. Navigate to the next page.

  5. The body background color doesn't changes anymore.

  6. Now disable JS and refresh the page it change the background color.

Screenshots or screencast

Screen.Recording.2025-07-25.at.10.53.30.AM.mov

Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: vipul0425 <[email protected]>
Co-authored-by: DAreRodz <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano changed the title [Type] Bug - Ignores <noscript> elements while preparing DOM. iAPI Router: Ignores <noscript> elements while preparing DOM. Jul 26, 2025
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity labels Jul 26, 2025
Copy link
Contributor

@DAreRodz DAreRodz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good to me. 👍

@vipul0425, could you include an entry in the CHANGELOG.md file of the Interactivity Router package? You can check the docs to know how to do so.

It would also be great to include some e2e tests. You would have to add a new test case to the router-styles.spec.ts file, and modify the related test blocks that live in /packages/e2e-tests/plugins/interactive-blocks.

Let me know if you need help with that. 🙂

@vipul0425 vipul0425 requested review from DAreRodz July 30, 2025 11:50
Copy link
Contributor

@DAreRodz DAreRodz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @vipul0425. Nice tests. 😎

I removed the nonexistent stylesheet because it was distorting the test result slightly, as it forced a page reload and prevented the style changes from being correctly tested. The rest of the test code is perfect as it is.

@DAreRodz DAreRodz enabled auto-merge (squash) July 31, 2025 12:21
@DAreRodz DAreRodz merged commit b769889 into WordPress:trunk Jul 31, 2025
59 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Jul 31, 2025
adamsilverstein pushed a commit to adamsilverstein/gutenberg that referenced this pull request Jul 31, 2025
…Press#70905)

* feat: Ignores <noscript> elements while preparing DOM.

* Docs: Update change logs with recent changes.

* feat: Adds e2e tests for noscript fix.

* docs: Added comment on code block.

* Remove nonexistent stylesheet from noscript tests

---------

Co-authored-by: vipul0425 <[email protected]>
Co-authored-by: DAreRodz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iAPI Router: Styles inside noscript tags are wrongly applied on client-side navigation
3 participants