•5 min read

React Hydration Failed: One Error Rebuilds the DOM, One Does Not

A teammate wrapped part of a product page in a <div> for a flex row, then deleted the flex. Nothing looked broken. The console disagreed:

Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client.

The diff underneath pointed at a <span> holding a build number. That span was fine. The div was sitting inside a <p> four lines further down. React reports where the two trees first disagree, not where you broke them.

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.

Same cause list, different machinery

Message one, for element and text differences:

Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client.

Message two, for attributes only:

A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up.

Both list the same five suspects (typeof window branches, Date.now(), 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 onRecoverableError, so it lands in your error tracker as minified #418. Message two is a development-only console.error and nothing at all in production.

Message one: the subtree is rebuilt

The server sent 3 minutes ago, the client produced 4:31 PM. The dev diff:

  <Card>
    <div className="card">
      <h2>
      <span className="time">
+       4:31 PM
-       3 minutes ago
      ...

+ is the client, - the server. The text ended up as 4:31 PM and the page still had one heading, so nothing duplicated. Harmless, until you check node identity. I kept a reference to a sibling <h1> 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.

Message two: the client value is discarded

Nobody warns you about this one. The server sent class="badge red", the client computed badge green. After hydration the element was still badge red. React kept the server's attribute and threw away the one it had just calculated.

And it does not heal. A re-render with the same tone changes nothing, because React's props for that node already say green, 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.

So an attribute mismatch already behaves as though suppressHydrationWarning were sitting on the element. Adding it only silences the message you were using to find the bug. Theme classes, aria-checked, data-* read from localStorage: 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 onRecoverableError call for it at all.

Half the time the parser wrote the bug

Architectural floor plan with dimension lines drawn at scale, the drawing rather than the building

I server-rendered a paragraph with a div inside it. React emitted exactly that and printed nothing, so the mistake leaves the server unchallenged:

<p>Intro text<div>block inside paragraph</div></p>

Then the parser gets involved, and it does not ask. Dumped from Chrome, that markup is three nodes: an empty <p> at the end, and the div hoisted out as its sibling. A bare <tr> gets a <tbody> wrapped around it. An <a> inside an <a> becomes two siblings.

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 <tbody> and the anchor was nested again, markup a parser would never produce. If a stylesheet depends on table > tbody > tr, it matches until hydration finishes, then stops.

What I check before touching the render function

Diff the HTML you sent against the DOM the browser built from it. curl -s "$URL" piped through grep, versus document.querySelector('#root').innerHTML 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.

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 typeof window branch, or a localStorage read during render.

React 19.3 added use(browser()) for subtrees that genuinely cannot render on the server. It suspends during SSR and renders normally on the client, so the isClient state dance can go. It wants a Suspense 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.

The Nuxt version of this has its own quirks, and the hydration mismatch walkthrough for Nuxt covers what changes there. The harness for this post is three files and about forty lines, and it lives in Snippet Ark under the two error strings as a title. I have pasted those strings into three bug reports this year.