Course contentsShow
← React
Lesson 1643 of 2,39640. Server-Side RenderingFree lesson

The Two-Pass Process: Server Render, Then Client Hydrate

Server renders HTML for fast first paint; client re-renders in memory to attach interactivity without replacing DOM.

The Two-Pass Process: Server Render, Then Client Hydrate

You'll learn: How React's SSR hydration happens in two distinct phases—server HTML generation followed by client-side attachment of interactivity.

The Two Distinct Passes

When you use server-side rendering, React doesn't just render once. It performs two separate renders of your component tree:

  1. Pass 1 (Server): Generates static HTML that's sent to the browser immediately
  2. Pass 2 (Client): Re-renders the component tree in memory to attach event listeners and interactivity

Why Two Passes?

Think of it like building a house. The server builds the structure—walls, floors, windows—and delivers a complete, viewable house instantly (fast first paint). Then the client comes in and wires the electricity—hooking up light switches, doorbells, and thermostats without tearing down any walls.

The server HTML shows users content immediately, but it's "dead"—clicking buttons does nothing yet. The client hydration pass recreates the same component tree in JavaScript memory, matches it to the existing DOM nodes, and attaches all the event handlers.

The In-Memory Reconciliation

Critically, hydration doesn't replace the DOM. React renders components on the client, compares the result to what's already in the browser, and reuses the existing nodes. It's only attaching the interactive layer—the onClick handlers, state management, and all the React machinery.

If there's a mismatch between what the server rendered and what the client expects, you'll see hydration errors.

Key Takeaway: SSR hydration is a two-pass process—the server renders HTML for instant display, then the client re-renders in memory to attach interactivity without destroying the initial DOM structure.