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-sideuseEffectround-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
windowreads 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?
Keep reading
Related articles from the SudoSecurity blog.
Building a Modern App With React, Vite, and Tailwind CSS: The Complete 2025 Guide
React for the UI, Vite for the build tooling, Tailwind for the styles. This is the stack most new frontend projects start with in 2025. This guide wires all three together from scratch and builds a real application structure you can actually start a production project from.
What is Vite? The Build Tool That Made Frontend Development Fast Again
Vite replaced Webpack for a lot of teams without much fanfare. Native ES modules, a dev server that starts in milliseconds, and a production build that doesn't require understanding 300 lines of config. Here's how it works and why the switch is worth it.
What is React? The JavaScript Library That Changed Frontend Development
React is a JavaScript library for building user interfaces. Facebook built it in 2013, open-sourced it, and the entire frontend ecosystem reorganized itself around it. Here is how the component model works, why it took over, and what you need to know before writing a single line.
Angular 18: Deferred Views & Built-in Control Flow
The newest release of Angular – which is Angular 18 – is planned to be released on May 22nd, 2024. This is Google's super popular TypeScript based webapp framework that allows developers to create amazing web applications. The features, changes, and goodies of this release are deferrable views…