Skip to content
Source
Sign inSign up
TanStack/redact

A `<noscript>` with an element inside fails hydration and replaces the server DOM #141

Openmamal72(GitHub profile, opens in a new tab) opened this issue 1 comment

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.1Redact 0.2.6
Server <p id="content"> keptyesno, replaced
pageerrornoneHydration 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.

  1. Thanks for the clear repro! This now has a tested local correction, and the exact size allowance is with Tanner.

    AI review notes: An owned document fixture reproduces the mismatch and replaces the content/noscript nodes on unchanged main in Chromium, Firefox and WebKit. Native React and the correction retain the server nodes, report no errors, and keep the neighboring button interactive. The fixture's head stayed intact on main, so this does not independently reproduce the larger app's full-head replacement. The correction resumes the opaque-noscript contract from #43, including ignored client fallback components, scalar text updates, and raw HTML transitions. It passes 2,080 local tests, types and build verification. The broader suspended-recovery work in #43 remains separate. Strict size checks still fail pending an exact allowance of up to 145 gzip or 188 Brotli bytes. The candidate is local, CI and review have not run for a submitted fix, and nothing for #141 is merged or released yet.

Sign in to join this conversation.