How does React handle hydration in Next.js?
Hydration is the step where React, in the browser, attaches event handlers and state to HTML that was already rendered on the server, turning static markup into an interactive app. In Next.js only Client Components hydrate; Server Component output stays as plain HTML.
The sequence on first load
- The server renders Server and Client Components to HTML and streams it, together with the RSC payload.
- The browser paints the HTML immediately, so content is visible before JavaScript runs.
- JavaScript for the Client Components downloads.
- React rebuilds the tree from the RSC payload, matches it against the existing DOM, and attaches listeners and state (
hydrateRoot). - Effects run; the page is interactive.
Streaming and selective hydration
With <Suspense>, React hydrates each boundary as soon as its HTML and code arrive, and it prioritizes boundaries the user interacts with. A slow widget does not delay interactivity elsewhere.
Why Server Components help
Server Component code is never hydrated or downloaded, so hydration work shrinks to the interactive islands. That improves Interaction to Next Paint (INP) and Total Blocking Time.
Hydration errors
React expects the first client render to match the server HTML. Differences (dates, random values, window checks, invalid HTML nesting, browser extensions changing the DOM) trigger a hydration error. Next.js 16.2 shows a + Client / - Server diff in the error overlay.
After hydration
Navigations do not hydrate again; React applies new RSC payloads to the live tree. Pages left behind can be kept hidden in <Activity> with Cache Components.
Code example
1// app/clock.tsx - hydration-safe time display2"use client";34import { useEffect, useState } from "react";56export function Clock({ serverTime }: { serverTime: string }) {7 // First client render matches the server HTML exactly8 const [time, setTime] = useState(serverTime);910 useEffect(() => {11 // Runs only after hydration, in the browser12 setTime(new Date().toLocaleTimeString());13 const id = setInterval(() => setTime(new Date().toLocaleTimeString()), 1000);14 return () => clearInterval(id);15 }, []);1617 return <time suppressHydrationWarning>{time}</time>;18}1920// app/page.tsx (Server Component)21// import { connection } from "next/server";22// await connection();23// <Clock serverTime={new Date().toLocaleTimeString("en-US", { timeZone: "UTC" })} />
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.