Next.jsMedium

What are React Server Components (RSC)?

React Server Components are components that render only on the server, ahead of time or per request. Their code never ships to the browser; instead, React sends a serialized description of the rendered UI (the RSC payload). They can be async and read data directly, and they compose with Client Components that handle interactivity.

Key properties

  • Zero client JavaScript for the component itself; only Client Components it renders are bundled.
  • Direct backend access: databases, file system, secrets, internal services.
  • Async/await in the component body.
  • No state or effects: useState, useEffect, event handlers and browser APIs are not available.
  • Can render Client Components and pass them serializable props or server-rendered children.

How they reach the browser

  1. On the server, React renders Server Components into the RSC payload: a streamed format with rendered elements, references to Client Component modules and their props.
  2. Next.js uses it to produce HTML for the first load.
  3. In the browser, React uses the payload to build the tree and hydrate Client Components.
  4. On navigation, only the RSC payload for changed segments is fetched.

Benefits

Smaller bundles, faster first load, no client-server waterfalls, secrets stay server-side, and large dependencies (markdown parsers, date libraries) stay on the server.

In Next.js

Every component in app/ is a Server Component unless its module (or an importing module) starts with "use client". With Cache Components, Server Component output can be cached with "use cache" and included in the static shell.

Interview tip

They are not the same as SSR. SSR turns any component into HTML; RSC changes where components run and what ships to the client. Client Components still get SSR'd.

Code example

tsx
1// app/blog/[slug]/page.tsx - Server Component
2import { marked } from "marked"; // large library: stays on the server
3import { readFile } from "node:fs/promises";
4import { CopyLink } from "./copy-link"; // Client Component
5
6export default async function Post({ params }: PageProps<"/blog/[slug]">) {
7 const { slug } = await params;
8 const md = await readFile(`content/${slug}.md`, "utf8"); // file system access
9 const html = await marked.parse(md);
10
11 return (
12 <article>
13 <div dangerouslySetInnerHTML={{ __html: html }} />
14 <CopyLink slug={slug} /> {/* only this ships JavaScript */}
15 </article>
16 );
17}
18
19// app/blog/[slug]/copy-link.tsx
20// "use client";
21// export function CopyLink({ slug }: { slug: string }) {
22// return <button onClick={() => navigator.clipboard.writeText(location.href)}>Copy link</button>;
23// }

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.

Open in study app