How does server-side rendering work in React?
ReactThe short answer
Server-side rendering (SSR) means the server runs your React components and generates HTML before sending it to the browser. The user sees a fully rendered page immediately instead of waiting for JavaScript to download and build the UI. After the HTML loads, React "hydrates" it on the client side to make it interactive.
The SSR process
- Browser requests a page
- Server runs React components and generates HTML
- Server sends the HTML to the browser
- Browser displays the HTML immediately (user can see content)
- Browser downloads the JavaScript bundle
- React hydrates the HTML — attaches event handlers and state
- Page is now fully interactive
Why use SSR
Faster first paint: The user sees content immediately because the server sends rendered HTML. With client-side rendering, the user sees a blank page until JavaScript loads and runs.
Better SEO: Search engine crawlers can read the server-rendered HTML directly. With client-side rendering, crawlers might see an empty page if they do not execute JavaScript.
Better for slow devices: Older phones and slow networks benefit from SSR because the heavy rendering work happens on the server, not on the user's device.
SSR with Next.js
Next.js is the most popular way to do SSR with React:
// Next.js App Router — server component by defaultasync function ProductPage({ params }) { const product = await fetch( `https://api.example.com/products/${params.id}` ).then((r) => r.json()); return ( <div> <h1>{product.name}</h1> <p>${product.price}</p> </div> );}The component runs on the server, fetches data, and sends the rendered HTML to the browser. The user does not wait for a loading spinner.
SSR tradeoffs
Pros:
- Faster initial page load
- Better SEO
- Works without JavaScript (the HTML is already there)
Cons:
- Server handles more work (rendering for every request)
- Time to interactive can be delayed (HTML is visible but not interactive until hydration completes)
- Some browser APIs (
window,localStorage) are not available on the server - More complex development and deployment
Things to watch out for
- No
windowordocumenton the server — useuseEffectfor client-only code - Hydration mismatches — the server HTML must match what the client renders
- Data fetching on the server — you need to fetch data before rendering, not in
useEffect
Interview Tip
Explain the SSR process step by step — server renders HTML, browser shows it, React hydrates. Cover the main benefits (performance, SEO) and the main challenges (no browser APIs on server, hydration mismatches). If the interviewer asks about frameworks, mention Next.js as the standard choice.
Why interviewers ask this
SSR is standard in modern React development, especially with Next.js. Interviewers want to see if you understand how it works, what problems it solves, and what challenges it introduces. This is especially important at companies that care about performance and SEO.