Skip to content

Lesson 8 of 14 · 20m

Server Components and Where Code Runs

RSC executes on the server and ships zero JavaScript — the serialization boundary, "use client" placement, and the real tradeoffs.

For a decade the model was fixed: ship JavaScript to the browser, run the components there, fetch the data there. React Server Components broke that. A component marked as server-side executes once — at build time or per request — against your database, filesystem, and secrets; what reaches the browser is a serialized description of its output plus the chunks of the tree that still need interactivity. The server component's code never ships. It has no useState, no useEffect, no onClick, because there is no browser to run them in — and it can await the database directly in render.

What actually crosses the wire

Next.js made this real with the App Router (stable in 13.4, May 2023); React 19 put the primitive in core. Everything in the tree defaults to server; a leaf opts into the client with the "use client" directive at the top of its file. Everything imported below that boundary is client code — the directive marks a boundary, not a file-level mode you sprinkle for convenience. That's the wrong mental model to attack first: "use client" at the top of page.tsx ships your entire page's JS again and you've re-created the old model with extra steps. The correct move is pushing the directive down to the interactive leaf — a <LikeButton> inside a server-rendered article.

Props crossing the boundary server→client must be serializable — no functions, no class instances (server actions, functions passed client→server, are the deliberate exception). The exception worth knowing is children: a server component can render client components as children, and a client component can receive server-rendered children through composition — <ClientPanel>{<ServerContent/>}</ClientPanel> works precisely because the children arrive already rendered. Importing the server component into the client file does not; that makes it client code.

And server components solve a real cost people forget: the classic react.dev example is a markdown renderer — rendered server-side, the parser's kilobytes of JS never reach the client at all.

What it buys, and what it costs

  • Bundle size: heavy dependencies — markdown parsers, date libraries, syntax highlighters — run on the server and ship nothing.
  • Data without waterfalls: the server component awaits the DB adjacent to the render, not through a client-side useEffect round-trip.
  • No client/server secret leakage — keys used in a server component physically cannot be in the bundle.
  • What hydration was costing: the old model downloaded every component's JS and re-executed it client-side to attach listeners — data plus code, twice. RSC makes the static parts of the tree free on the client, which is where the real speedup lives.

The cost is real: a new execution environment to reason about, a serialization boundary in the middle of your component tree, and a hard dependency on a framework that implements the feature (Next.js, React Router's RSC mode). A CSR-only app gains nothing here — it's the model for server-rendered apps, not a universal upgrade.

Field notes

  • Hydration mismatches — server HTML vs first client render disagreeing — got actual diff output in React 19's error handling; they're usually timestamps, random values, or window reads in client components.
  • use() lets a client component unwrap a promise a server component handed it — the clean pattern for passing server work into client interactivity.
  • Keep "use client" leaves small and high in the DOM but low in the component tree: server components fetch and render; the leaf handles the click.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.