Hydration

2 min read

i once tapped a like button on a news site the second the article appeared. nothing happened. i tapped again. the heart filled, the count jumped by two, and the page shifted half a pixel. the ui was already on screen. the app was not ready yet.

that gap has a name: hydration.

what it is

rendering builds ui from scratch. hydration does something stranger: the html is already on screen, so react walks the same component tree and wires up state, events, and effects without repainting the whole thing.

hydration is not download. it is the handshake between static html and live client code.

the five phases

phase 2 is the trap. users think the app loaded because they can read it. developers think it broke because onClick does nothing. both are half right.

the server renders first — no window, no localStorage, no pointer events. the browser paints real layout. then javascript downloads, react aligns its client tree with the server html, and only then do clicks actually work. heavy bundles stretch phase 3; a huge component tree makes phase 4 feel like a freeze on a phone.

when hydration breaks

if server html and client render disagree, you get a hydration mismatch:

server html:  <button class="primary">save</button>
client render: <button class="primary" disabled>save</button>
result: react warns, may re-render, layout can shift

usual suspects: Date.now() in render, browser-only apis on first paint, invalid html nesting, extensions mutating the dom before react runs.

ssr trades a visible-but-dead window for earlier content. client-only rendering trades a blank screen for a simpler model. neither is free.

what actually helps

  • keep client bundles smaller
  • do not put non-deterministic values in server-rendered markup
  • use suppressHydrationWarning only for known safe cases (theme class on <html>), not as a blanket fix
  • split heavy widgets into client islands that hydrate after the shell
  • measure time to interactive, not just first contentful paint

the rule i remember

if the user can see it, assume they will click it. hydration is the invisible phase where the page is a screenshot with ambitions.

ssr gives you a head start on content. hydration is the price of making that content real.