Writing
React Server-Side Rendering With Next.js: What Changed and When It Matters
Server-render the first view of any React page that needs to load fast or rank, and keep client-side rendering for apps behind a login. Next.js is still the easiest route, and React’s docs now recommend a framework.
By Ka Lun Chan · Web development / Architecture
Should a React app render on the server or in the browser?
Render the first view on the server, or at build time, for any page that needs to load fast or be found in search. Client-side rendering is fine for apps behind a login. Next.js is still the easiest way I know to get server rendering with React, and React’s own docs now recommend starting with a framework like it.
I first wrote this on my old blog. This version keeps the advice that held up and updates what changed, which is a lot: the tooling, the defaults and the number of rendering modes you can choose from.
| Rendering mode | How it works | Good for | Catch |
|---|---|---|---|
| Client-side rendering | The server sends an HTML shell and a JavaScript bundle. The browser fetches data and builds the page. | Dashboards, internal tools, apps behind a login | Nothing useful shows until the JavaScript runs, and bots that don’t run JavaScript see an empty shell |
| Server-side rendering | The server renders HTML for each request, then the browser hydrates it so it becomes interactive | Personalized or fast-changing pages that still need to load quickly and be indexed | You run and pay for a Node server, and every request costs render time |
| Static generation | Pages are rendered to HTML once at build time and served as files from a CDN | Marketing sites, docs, blogs | Changing content means rebuilding and redeploying |
| Incremental static regeneration | Static pages are regenerated in the background after a set interval or on demand | Large content sites and catalogs that change through the day | Next.js specific, needs the Node runtime, and some visitors get a stale page |
| Streaming | The server sends the page shell first and fills in slower parts as their data arrives | Pages with one slow data source next to fast ones | You have to design loading states for every boundary |
What’s the difference between client-side and server-side rendering?
With server-side rendering, the server sends finished HTML for the first request, so the page appears before any JavaScript downloads. With client-side rendering, the server sends a shell and JavaScript, and the browser builds the content after another request for data.
Server rendering is how the web always worked. Frameworks like Ruby on Rails and languages like PHP render HTML on the server for every request. React can do both: render in the browser, or render the same components on the server.
The most common use of server rendering in a React app is the initial request. When a person or a bot asks for a page, the server returns the HTML along with the CSS and JavaScript. The reader sees content right away instead of a white page waiting for a bundle to download and run. React then hydrates that HTML, attaching event handlers so the page becomes interactive.
Client-side rendering earns its place after that first load. The browser can update parts of the page without reloading all of it, which gives a smoother experience inside an app. Most server-rendered React apps do exactly this: server for the first view, client for everything after.
When I first wrote this, I said server rendering was SEO friendly with all the search engines. That needs a qualification now. Google’s JavaScript SEO guide says Googlebot crawls a page, puts it in a rendering queue, renders it with headless Chromium and then indexes the rendered HTML. That queue can take seconds or longer. Google still calls server-side rendering or pre-rendering “still a great idea” because it’s faster for users and crawlers, and because not every bot runs JavaScript. I covered why that matters for publishers in what publishing taught me about SEO, AEO and GEO.
Why is server-side rendering with React harder?
Because the same components now run in two places. They have to work on Node as well as in the browser, routing has to work on both sides, and code that touches browser APIs or makes data requests behaves differently on the server.
That was my main point in the original, and it still holds if you build server rendering yourself. A hand-rolled setup meant a Node server, a client router and a server router that had to agree on every URL, and data fetching that ran once on the server and then again, or not at all, in the browser. Anything that touched window or localStorage broke on the server until you guarded it. Hydration mismatches, where the server HTML and the first client render disagree, are still a common bug.
Frameworks absorb most of this. They own the router, so one route definition serves both sides, and they decide where data loads. The complexity doesn’t disappear, but it moves into code you didn’t have to write. If you want the lifecycle side of this, my post on the React component lifecycle covers what runs where.
Is Next.js still the easiest way to server-render React?
For most teams, yes. When I first wrote this, I had tried other React server rendering setups and Next.js was the easiest to learn and deploy. It has grown a lot since, but automatic code splitting and server rendering by default are still the core of it.
Back then Next.js was a small framework from a company called ZEIT, built on React, Webpack and Babel, and its repository lived under zeit/next.js. ZEIT renamed itself Vercel, and the project now lives at vercel/next.js. The quick start I recommended was a community tool called create-next-app. That has been replaced by an official create-next-app, which sets up TypeScript, ESLint, Tailwind and the App Router by default and needs Node 20.9 or later:
npx create-next-app@latest my-app --yes
cd my-app
npm run devThe bigger change is the App Router and React Server Components. In the original Pages model, every component shipped to the browser. Now components are Server Components by default: they render on the server, either at build time or per request, and their code stays out of the client bundle. You mark the interactive parts with 'use client'. Next.js also supports static generation, incremental static regeneration, streaming with loading.js or Suspense, and a fully static export you can host anywhere.
The tutorial site I linked to is gone. The free official course is at nextjs.org/learn, and the examples folder is still in the repository.
What does server rendering look like in the App Router?
A page is an async function. It awaits its data on the server and returns JSX, and only the components marked 'use client' send JavaScript to the browser.
// app/posts/page.js
// A Server Component: it runs on the server, so this code never reaches the browser.
import LikeButton from './like-button';
export default async function Page() {
const res = await fetch('https://api.example.com/posts');
if (!res.ok) throw new Error('Failed to load posts');
const posts = await res.json();
return (
<ul>
{posts.map((post) => (
<li key={post.id}>
{post.title} <LikeButton />
</li>
))}
</ul>
);
}// app/posts/like-button.js
// A Client Component: rendered to HTML on the server, then hydrated in the browser.
'use client';
import { useState } from 'react';
export default function LikeButton() {
const [liked, setLiked] = useState(false);
return (
<button type="button" aria-pressed={liked} onClick={() => setLiked(!liked)}>
{liked ? 'Liked' : 'Like'}
</button>
);
}There’s no separate server router, no getInitialProps and no data fetched twice. The Next.js data fetching guide notes that fetch isn’t cached by default, so this page renders per request. Add export const revalidate = 3600 to turn it into an ISR page that regenerates at most once an hour. If the API is slow, a loading.js file next to the page lets Next.js stream a loading state first. Bots get the finished page rather than the stream, which keeps crawlers happy.
When is client-side rendering fine, and what are the alternatives?
Client-side rendering is fine when search and first-load speed don’t matter much, such as a dashboard behind a login. For public pages, React’s docs recommend a framework, and Next.js is one of several good choices.
The React docs now recommend starting a new app with a framework, list Next.js and React Router first, and note that these frameworks can also produce client-rendered single-page apps or static sites with no server. Building from scratch with Vite is described as the path when your constraints don’t fit a framework. The options I’d weigh:
- React Router in framework mode adds loaders, actions and SPA, SSR or static rendering through a Vite plugin. It’s the natural step up if you already use React Router.
- Astro renders components, React ones included, to plain HTML and only hydrates the ones you mark with a
client:*directive. It’s a strong fit for content sites with a few interactive pieces. - A plain Vite single-page app with prerendering. Vite’s SSR guide calls its server rendering API low level and meant for framework authors, but it also shows how to prerender routes to static HTML.
That last option is what this site uses. It’s a React app built with Vite, and a small script renders every route to static HTML at build time, so the pages are plain files with no Node server behind them. It works because the content changes only when I publish. A site with logged-in users or constantly changing data would be better served by a framework. If offline support matters more than search, look at progressive web apps as well.
Sources
Checked in November against the Next.js documentation and repository, the React docs on creating an app and on Server Components, the React Router, Astro and Vite guides, and Google Search Central’s JavaScript SEO basics. The opinion on Next.js and the comparison table are mine.
- Next.js Docs: Installation (create-next-app)
- Next.js Docs: Fetching Data and streaming
- Next.js Docs: Incremental Static Regeneration
- Next.js Docs: Static Exports
- Next.js Learn: free official course
- GitHub: vercel/next.js
- Vercel blog: ZEIT is now Vercel
- React Docs: Creating a React App
- React Docs: Server Components
- React Router Docs: Picking a mode
- Astro Docs: Islands architecture
- Vite Docs: Server-Side Rendering
- Google Search Central: Understand JavaScript SEO basics
Short answers
What is the difference between client-side and server-side rendering in React?
With server-side rendering, the server sends finished HTML for the first request, so the page appears before any JavaScript downloads, and React then hydrates it. With client-side rendering, the server sends a shell and JavaScript, and the browser fetches data and builds the content itself.
Does Google need server-side rendering to index a React app?
Not strictly. Googlebot renders JavaScript pages with headless Chromium after a rendering queue that can take seconds or longer. Google still recommends server-side rendering or pre-rendering because it is faster for users and crawlers, and not every bot runs JavaScript.
Is Next.js still the easiest way to server-render React?
For most teams, yes. The official create-next-app sets up the App Router, where components render on the server by default and only components marked use client send JavaScript to the browser. React Router in framework mode and Astro are good alternatives.
When is client-side rendering fine?
When search and first-load speed matter less, such as a dashboard or internal tool behind a login. Public pages that need to load quickly or be found in search should be server-rendered or prerendered at build time.
Pick the mode per page
List your routes and mark each one public or behind a login, and static or changing. That list tells you which rendering mode each page needs and whether you need a framework at all.