CSR, SSR, and static rendering concepts
Client-side rendering, server-side rendering, and static generation compared, plus what hydration actually does and why the tradeoffs differ.
Concurrent rendering and transitionsSetting up a React project
CSR, SSR, and static rendering concepts
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Client-side rendering ships a mostly empty HTML shell and a JavaScript bundle; the browser has to download and run that bundle before the user sees anything meaningful.
- Server-side rendering runs your component tree on a server for every request and sends back real HTML, so the first paint shows content before any JavaScript has loaded.
- Static generation runs the same rendering work once, at build time, and serves the resulting HTML file to every visitor, trading per-request freshness for the cheapest possible hosting.
- Hydration is React re-running your components in the browser against HTML it did not create, so it can attach event listeners and state to markup that already exists on the page.
- A server-rendered page can look fully interactive while it is actually a 'dead' page waiting to hydrate — clicking a button before hydration finishes does nothing.
- None of this is a Next.js feature. CSR, SSR, SSG, and hydration are rendering strategies React itself defines; a framework's job is to wire a build system and a server around them.
Three ways to get HTML in front of a user
Every React app eventually has to answer one question: where does the HTML that the browser first paints come from? There are three answers, and they are rendering strategies, not products — React itself defines all three, and a framework’s job is to choose one (or several) and wire the plumbing around it.
Client-side rendering (CSR) sends the browser almost nothing. A typical CSR response looks like this:
<!doctype html>
<html>
<body>
<div id="root"></div>
<script src="/bundle.js"></script>
</body>
</html>
The real work happens after that script loads:
import { createRoot } from "react-dom/client";
import App from "./App";
createRoot(document.getElementById("root")).render(<App />);
Nothing exists in the page until bundle.js downloads, parses, executes, and createRoot builds the whole UI from scratch in the browser. A fast connection hides this; a slow one shows a blank page or a spinner for a noticeable stretch.
Server-side rendering (SSR) does that same rendering work, but on a server, for each incoming request, and sends the result as HTML:
import { renderToString } from "react-dom/server";
import App from "./App";
function handleRequest(req, res) {
const html = renderToString(<App />);
res.send(`
<!doctype html>
<html><body>
<div id="root">${html}</div>
<script src="/bundle.js"></script>
</body></html>
`);
}
The browser now has real content on the very first response — headings, text, images — before any JavaScript has run. That matters for anyone scanning the page quickly, for search engines, and for anyone on a slow connection.
Static site generation (SSG) runs that exact same rendering step once, ahead of time, during a build, and writes the output to a plain HTML file that a server (or a CDN) just hands out unchanged to every visitor. There is no per-request rendering cost at all, because the work already happened before any user showed up.
Why a server-rendered page isn’t interactive yet
Sending HTML solves the “nothing to look at” problem, but HTML alone has no behavior. A button rendered by renderToString is just a <button> tag; it has no click handler attached, because attaching a handler is something only running JavaScript can do.
This is where hydration comes in. The same bundle that CSR relies on to build the page from scratch is, in SSR and SSG, used instead to attach itself to HTML that already exists:
import { hydrateRoot } from "react-dom/client";
import App from "./App";
hydrateRoot(document.getElementById("root"), <App />);
hydrateRoot walks the existing DOM, matches it against what rendering <App /> would produce, and wires up event listeners, state, and effects onto that markup instead of replacing it. Picture a stage set that a crew already built overnight: the audience can see the set the moment the curtain opens, but the actors (the event handlers) only take their places once they walk out and start the show. Between “curtain opens” and “actors in place,” the set looks finished but nothing on it responds yet — that gap is why a server-rendered page can look fully loaded while a click on it still does nothing.
This also explains a real failure mode called a hydration mismatch: if the HTML React receives doesn’t match what the component would render client-side (say, a server clock reading a different second than the client’s), React has to patch the difference and may log a warning or discard the mismatched markup.
Weighing the tradeoffs
No single strategy wins everywhere:
- Time to first byte and first paint. SSG is fastest, since the HTML is already sitting on a CDN. SSR is close behind, paying only the cost of rendering per request. CSR is slowest to show anything, since the browser must fetch and run JavaScript first.
- Time to interactive. All three eventually need the same JavaScript bundle to become interactive. CSR and SSR/SSG converge here; the difference is only in what the user sees before that point.
- SEO and link previews. Crawlers and chat/social unfurlers that don’t execute JavaScript see only the initial HTML. SSR and SSG hand them real content; CSR hands them an empty shell unless the crawler specifically runs JavaScript.
- Freshness vs. build complexity. SSG requires a rebuild to reflect new data, which is fine for a blog post and wrong for a stock ticker. SSR recomputes every request, which is always fresh but costs server compute on every single visit. CSR sidesteps server compute entirely by pushing everything to the client, at the cost of that initial blank-page delay.
In practice, real apps mix these per-route: a marketing page as SSG, a dashboard as SSR, and a highly interactive editor as CSR, all within one project.
What the video covers
Theo’s video walks through CSR, SSR, hydration (including the “dead button” problem — a button that looks clickable before hydration finishes but does nothing yet), and static/build-time generation as the general rendering model, which matches this lesson’s scope well. It is long (about 49 minutes) and spends its second half on newer, more advanced ideas — server islands, partial prerendering, and Suspense-based streaming — that go past what this lesson covers; treat those as a preview of later lessons rather than required material here. The video demonstrates several of these ideas inside Next.js, but its explanation of CSR, SSR, SSG, and hydration themselves stays at the level of the React/web rendering model, not Next.js-specific file conventions, which is the same split this lesson draws.
Where this fits
With the three rendering strategies and hydration in hand, the next question is which parts of a React tree run on the server versus the client at all — covered in Server Components vs. Client Components.
Check yourself
Why can a server-rendered page look complete on first paint but not respond to a click yet?
The server sent real HTML, so the browser can paint it immediately, but no event listeners exist until React hydrates the page by re-running the component tree client-side and attaching its handlers; a click before that finishes has nothing to call.
What is the main cost static generation accepts in exchange for its speed and cheap hosting?
The HTML is only as fresh as the last build. If the underlying data changes after the build runs, every visitor sees the stale version until the site is rebuilt and redeployed, unlike server rendering which recomputes on every request.
Is hydration a Next.js-specific mechanism?
No. Hydration is a capability of the React runtime itself — `hydrateRoot` from `react-dom/client` — that any server-rendering setup calls after sending HTML. Next.js, Remix, and a hand-rolled Express server all rely on the same underlying React behavior.
Why does pure client-side rendering tend to hurt SEO and perceived performance compared to SSR or SSG?
A crawler or a user that only sees the initial HTML gets an empty shell, because the real content only exists after JavaScript downloads, parses, and runs; SSR and SSG instead deliver the finished content as the very first response.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.