A `<noscript>` with an element inside fails hydration and replaces the server DOM #141
Version: @tanstack/redact 0.2.6 via withRedact, Next.js 16.4.3 (App Router, Turbopack, production), react/react-dom 19.3.1, Chromium.
What happens#
A <noscript> that contains an element, such as Google Tag Manager's <noscript><iframe …></noscript>, makes Redact report Hydration mismatch. and replace the server-rendered DOM. React 19.3.1 hydrates the same page with no errors and keeps the server nodes.
Repro#
// app/noscript/page.jsx
export default function Page() {
return (
<main>
<p id="content">Page content</p>
<noscript>
<iframe src="about:blank" height="0" width="0" style={{ display: 'none' }} title="No script" />
</noscript>
</main>
)
}
next build && next start, then load /noscript, with and without withRedact:
| React 19.3.1 | Redact 0.2.6 | |
|---|---|---|
Server <p id="content"> kept | yes | no, replaced |
pageerror | none | Hydration mismatch. |
Impact#
GTM's snippet sits at the end of the root layout's <body>, so every page fails hydration and the whole document is rebuilt, including the <head> (about 120 elements in our app).
Where#
With scripting enabled, the browser parses a <noscript>'s content as text, so the server's <iframe> never exists as an element. React treats noscript as a text-content element and doesn't hydrate its children. Redact appears to hydrate them as elements and finds only text.
Passing the same content as markup hydrates cleanly, and works as a workaround for now:
<noscript dangerouslySetInnerHTML={{ __html: '<iframe src="…" height="0" width="0" style="display:none" title="…"></iframe>' }} />
Related: #43 includes a change that keeps <noscript> content opaque during hydration, which may cover this. It hasn't landed yet and currently conflicts with main.
Sign in to join this conversation.
Thanks for the clear repro! This now has a tested local correction, and the exact size allowance is with Tanner.