[{"data":1,"prerenderedAt":6},["ShallowReactive",2],{"post-content-react-hydration-mismatch-text-vs-attribute":3},{"content":4,"lastModified":5},"\u003Cp>A teammate wrapped part of a product page in a \u003Ccode>&lt;div&gt;\u003C\u002Fcode> for a flex row, then deleted the flex. Nothing looked broken. The console disagreed:\u003C\u002Fp>\n\n\u003Cblockquote>Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client.\u003C\u002Fblockquote>\n\n\u003Cp>The diff underneath pointed at a \u003Ccode>&lt;span&gt;\u003C\u002Fcode> holding a build number. That span was fine. The div was sitting inside a \u003Ccode>&lt;p&gt;\u003C\u002Fcode> four lines further down. React reports where the two trees first disagree, not where you broke them.\u003C\u002Fp>\n\n\u003Cp>Here is what I had wrong for years: React 19 has two hydration mismatch errors, and they do unrelated things to your DOM. I ran both through a small harness on React 19.3.1 to see what landed in the browser.\u003C\u002Fp>\n\n\u003Ch2>Same cause list, different machinery\u003C\u002Fh2>\n\n\u003Cp>Message one, for element and text differences:\u003C\u002Fp>\n\n\u003Cblockquote>Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client.\u003C\u002Fblockquote>\n\n\u003Cp>Message two, for attributes only:\u003C\u002Fp>\n\n\u003Cblockquote>A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up.\u003C\u002Fblockquote>\n\n\u003Cp>Both list the same five suspects (\u003Ccode>typeof window\u003C\u002Fcode> branches, \u003Ccode>Date.now()\u003C\u002Fcode>, locale formatting, changing data, invalid nesting) plus browser extensions, which is why people treat them as one bug. What differs is what happens next, and where it gets reported. Message one reaches \u003Ccode>onRecoverableError\u003C\u002Fcode>, so it lands in your error tracker as minified #418. Message two is a development-only \u003Ccode>console.error\u003C\u002Fcode> and nothing at all in production.\u003C\u002Fp>\n\n\u003Ch2>Message one: the subtree is rebuilt\u003C\u002Fh2>\n\n\u003Cp>The server sent \u003Ccode>3 minutes ago\u003C\u002Fcode>, the client produced \u003Ccode>4:31 PM\u003C\u002Fcode>. The dev diff:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>  &lt;Card&gt;\n    &lt;div className=\"card\"&gt;\n      &lt;h2&gt;\n      &lt;span className=\"time\"&gt;\n+       4:31 PM\n-       3 minutes ago\n      ...\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>\u003Ccode>+\u003C\u002Fcode> is the client, \u003Ccode>-\u003C\u002Fcode> the server. The text ended up as \u003Ccode>4:31 PM\u003C\u002Fcode> and the page still had one heading, so nothing duplicated. Harmless, until you check node identity. I kept a reference to a sibling \u003Ccode>&lt;h1&gt;\u003C\u002Fcode> before hydration and compared it afterwards: different object. Every node under the mismatch had been replaced. Whatever a user typed into that part of the page is gone, and every effect in the subtree runs a second time.\u003C\u002Fp>\n\n\u003Ch2>Message two: the client value is discarded\u003C\u002Fh2>\n\n\u003Cp>Nobody warns you about this one. The server sent \u003Ccode>class=\"badge red\"\u003C\u002Fcode>, the client computed \u003Ccode>badge green\u003C\u002Fcode>. After hydration the element was still \u003Ccode>badge red\u003C\u002Fcode>. React kept the server's attribute and threw away the one it had just calculated.\u003C\u002Fp>\n\n\u003Cp>And it does not heal. A re-render with the same \u003Ccode>tone\u003C\u002Fcode> changes nothing, because React's props for that node already say \u003Ccode>green\u003C\u002Fcode>, so there is no diff to push to the DOM. The stale value survives until the prop becomes something new. I checked after hydration, after a no-op render, and after a real change: only the last moved the class.\u003C\u002Fp>\n\n\u003Cp>So an attribute mismatch already behaves as though \u003Ccode>suppressHydrationWarning\u003C\u002Fcode> were sitting on the element. Adding it only silences the message you were using to find the bug. Theme classes, \u003Ccode>aria-checked\u003C\u002Fcode>, \u003Ccode>data-*\u003C\u002Fcode> read from \u003Ccode>localStorage\u003C\u002Fcode>: all of it stays at the server's value while your code believes otherwise. In a production build there was no console output and no \u003Ccode>onRecoverableError\u003C\u002Fcode> call for it at all.\u003C\u002Fp>\n\n\u003Ch2>Half the time the parser wrote the bug\u003C\u002Fh2>\n\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fimages.pexels.com\u002Fphotos\u002F4458205\u002Fpexels-photo-4458205.jpeg?auto=compress&amp;cs=tinysrgb&amp;w=1200\" alt=\"Architectural floor plan with dimension lines drawn at scale, the drawing rather than the building\" loading=\"lazy\" width=\"1200\" height=\"801\">\u003C\u002Fp>\n\n\u003Cp>I server-rendered a paragraph with a div inside it. React emitted exactly that and printed nothing, so the mistake leaves the server unchallenged:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>&lt;p&gt;Intro text&lt;div&gt;block inside paragraph&lt;\u002Fdiv&gt;&lt;\u002Fp&gt;\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>Then the parser gets involved, and it does not ask. Dumped from Chrome, that markup is three nodes: an empty \u003Ccode>&lt;p&gt;\u003C\u002Fcode> at the end, and the div hoisted out as its sibling. A bare \u003Ccode>&lt;tr&gt;\u003C\u002Fcode> gets a \u003Ccode>&lt;tbody&gt;\u003C\u002Fcode> wrapped around it. An \u003Ccode>&lt;a&gt;\u003C\u002Fcode> inside an \u003Ccode>&lt;a&gt;\u003C\u002Fcode> becomes two siblings.\u003C\u002Fp>\n\n\u003Cp>React compares its tree against a DOM that has already been rearranged, fails, and rebuilds. Now the same page has two structures: the browser's repaired version before hydration, React's literal version after. Post-rebuild there was no \u003Ccode>&lt;tbody&gt;\u003C\u002Fcode> and the anchor was nested again, markup a parser would never produce. If a stylesheet depends on \u003Ccode>table &gt; tbody &gt; tr\u003C\u002Fcode>, it matches until hydration finishes, then stops.\u003C\u002Fp>\n\n\u003Ch2>What I check before touching the render function\u003C\u002Fh2>\n\n\u003Cp>Diff the HTML you sent against the DOM the browser built from it. \u003Ccode>curl -s \"$URL\"\u003C\u002Fcode> piped through grep, versus \u003Ccode>document.querySelector('#root').innerHTML\u003C\u002Fcode> in the console. Attribute order will differ, so look for moved nodes. If nodes moved, the parser is the author and your component is innocent.\u003C\u002Fp>\n\n\u003Cp>If nothing moved, a value differs between environments, and the error type narrows it. Text or structure means the render path is unstable: move the read into an effect, or pin the locale and timezone. Attribute only usually means the value never reached the server: a \u003Ccode>typeof window\u003C\u002Fcode> branch, or a \u003Ccode>localStorage\u003C\u002Fcode> read during render.\u003C\u002Fp>\n\n\u003Cp>React 19.3 added \u003Ccode>use(browser())\u003C\u002Fcode> for subtrees that genuinely cannot render on the server. It suspends during SSR and renders normally on the client, so the \u003Ccode>isClient\u003C\u002Fcode> state dance can go. It wants a \u003Ccode>Suspense\u003C\u002Fcode> boundary above it, only works from a client component, and drops those nodes out of the server HTML. Keep it for the widget, not the page.\u003C\u002Fp>\n\n\u003Cp>The Nuxt version of this has its own quirks, and the \u003Ca href=\"\u002Fposts\u002Fnuxt-hydration-mismatch-find-the-cause\u002F\">hydration mismatch walkthrough for Nuxt\u003C\u002Fa> covers what changes there. The harness for this post is three files and about forty lines, and it lives in \u003Ca href=\"\u002Fsnippetark\u002F\">Snippet Ark\u003C\u002Fa> under the two error strings as a title. I have pasted those strings into three bug reports this year.\u003C\u002Fp>\n","2026-11-19",1795678594116]