React Server Components: Reading the Server/Client Boundary
React Server Components decide where code runs through the import graph. Here's what crosses the boundary, what leaks into the bundle, and how to review it.
Open a file in an App Router codebase and try to say where its code runs. With React Server Components, the answer isn't in the file. It's in the import graph above it, and that is the main reason RSC codebases are harder to read and review than the React apps that came before them.
A ProductCard can run only on the server, or on the server and again in the browser, and nothing in its body tells you which. You find out by walking up its importers until you hit a file that starts with "use client", or run out of files. That walk is easy to skip in review, because a diff doesn't show the boundary moving.
This post is for the lead who reviews and maintains one of these codebases: what the directive marks, what crosses the boundary, what leaks into the bundle, where data fetching went, and a script plus a checklist for mapping every boundary in an existing repo.
The React docs are precise about this, and most mental models aren't. The directive marks "the module and its transitive dependencies as client code." It draws a line in the module dependency tree, not the render tree. A component usage is a Client Component when it's defined in a 'use client' module or is a transitive dependency of one. Everything else is a Server Component.[1]
Two things follow from that, and both trip people up. First, the directive belongs on the entry file only. Every module the entry imports joins the client graph whether or not it has its own directive, so sprinkling "use client" on every file inside a subtree adds noise without changing anything. Second, the same module can live in both graphs. A lib/format.ts imported by a Server Component and by a Client Component is compiled for each environment, so it runs on the server for one caller and ships to the browser for the other.
"Client" doesn't mean "browser only" either. The Next.js boundary guide puts it in one table: a Server Component runs on the server and never in the browser, while a Client Component renders on the server for the initial HTML and again in the browser during hydration.[2]
On the server
In the browser
Server Component
Yes
No
Client Component
Yes
Yes
So in review, don't ask whether something renders on the server; both kinds do. Ask whether its code ships to the browser. And note that there is no directive for Server Components at all. They're the default, and "use server" isn't the opposite of "use client": it marks Server Functions.
The Next.js docs reduce the boundary to two rules. Code crosses through imports: whatever a Client Component imports is pulled into the client bundle. Data crosses through props, and it has to be serializable. Every review question about RSC falls under one of those two.
Props from a Server Component to a Client Component are serialized into the RSC Payload. Primitives, plain objects, arrays, Map, Set, Date, promises and JSX elements are fine. Class instances, ordinary functions and unregistered symbols are not. Passing an onClick handler from a server file to a client one throws.
The exception is a Server Function. Put "use server" at the top of an async function or a module, and those functions cross as references the client can call over the network. The React docs are blunt about what that means: the arguments are "fully client-controlled," so treat them as untrusted input, validate them, and check inside every Server Function that the signed-in user is allowed to do the thing.[3]
I review Server Functions with the same checklist I use for HTTP handlers, because a client can call them with whatever arguments it likes.
Here is the whole pattern in four small files. The page and the data module stay on the server. Only the button and a reference to archivePost reach the browser.
ts
// lib/posts.tsimport "server-only";import { db } from "./db";export type PostSummary = { id: string; title: string; archived: boolean };export async function getPosts(): Promise<PostSummary[]> { return db.post.findMany({ select: { id: true, title: true, archived: true } });}
ts
// app/posts/actions.ts"use server";import { revalidatePath } from "next/cache";import { db } from "@/lib/db";import { getCurrentUser } from "@/lib/auth";export async function archivePost(postId: string) { // Arguments come from the client: validate them like request input. if (typeof postId !== "string" || postId.length === 0) throw new Error("Invalid post id"); const user = await getCurrentUser(); if (!user?.canEdit) throw new Error("Not allowed"); await db.post.update({ where: { id: postId }, data: { archived: true } }); revalidatePath("/posts");}
// app/posts/page.tsximport { getPosts } from "@/lib/posts";import { ArchiveButton } from "./archive-button";export default async function PostsPage() { const posts = await getPosts(); // runs on the server, during render return ( <ul> {posts.map((post) => ( <li key={post.id}> {post.title} {!post.archived && <ArchiveButton postId={post.id} />} </li> ))} </ul> );}
What crosses is exactly two things: postId, a string, and archivePost, a Server Function reference. The database client, the query and the auth lookup never enter the client graph, because the only client file imports ./actions, and a "use server" module hands the client references, not code.
This half doesn't show up in a diff. Add one import to a client file and you may have pulled a date library, a markdown parser or a config module into the browser bundle. The React docs use exactly this example: rendering markdown on the client means users download and parse "an additional 75K (gzipped) of libraries," while a Server Component keeps those libraries out of the bundle entirely.[4]
Secrets are the scarier case, though Next.js limits the damage. Only environment variables prefixed NEXT_PUBLIC_ are included in the client bundle, and others are replaced with an empty string, so a server key usually doesn't leak; the code just breaks quietly. The fix the docs recommend is the server-only package. Import it at the top of any module that must never reach the client, as lib/posts.ts does above, and an accidental client import becomes a build-time error instead of a silent one.[5]
Before RSC, data entered the tree from a loader such as getServerSideProps or from a useEffect fetch, then flowed down as props. Now an async Server Component awaits its own data during render, straight from the database, with no API route in between. That's a real simplification for the author and a new place for bugs to hide for the reviewer.
The current Next.js docs are explicit that fetch requests are not cached by default. Identical requests are memoized within one render, React.cache deduplicates ORM calls within a single request only, and caching across requests is something you opt into with the 'use cache' directive under Cache Components.[6]
When I read an RSC codebase, I look for three things here: data fetched in a Client Component's effect when its Server Component parent could have fetched it, sequential awaits that should be one Promise.all, and caching assumptions copied from older App Router tutorials.
# The contrarian part: most "use client" lines sit too high
My opinion, stated plainly: the most common RSC mistake isn't a leaked secret. It's a boundary drawn one or two levels too high. The directive lands on a page or layout because one button needs useState, and the whole subtree follows it into the bundle. It happens because adding "use client" to the file you're editing is the fastest way to make a compiler error go away, and the diff doesn't make it obvious where the line ended up.
The second opinion is less popular. RSC trades bundle size for a harder mental model. The bytes saved are real. But the cost moved into reading. You need the import graph to know where code runs, and "parent" no longer means "owner." In the Next.js docs' own example, a client Modal renders a server Cart it never imported, because Page owns the JSX and passes Cart in as children. That's elegant. It's also something a new hire won't infer from the file in front of them. Hidden structure like that is one of the reasons a codebase gets harder to understand than it needs to be.
Figure 1. Code crosses the boundary through imports and joins the bundle; data crosses as serialized props, and server content can sit inside a client shell as children.
# Mapping the boundaries in a React Server Components codebase
Don't start from components. Start from entry points. Every "use client" file is the root of a client subtree, so listing them gives you the client graph's roots in one pass. A plain grep for the string gives false positives, such as seed data, docs and test fixtures that merely contain it, so check the file prologue, the only place the directive counts.
js
// client-entries.mjs: list every "use client" entry point and its direct imports.// Usage: node client-entries.mjs srcimport { readFileSync, readdirSync } from "node:fs";import { join } from "node:path";const root = process.argv[2] ?? "src";const files = readdirSync(root, { recursive: true }) .map(String) .filter((f) => /\.(jsx?|tsx?)$/.test(f) && !f.includes("node_modules"));// The directive must come first; only comments may precede it.const prologue = /^(?:\s|\/\/[^\n]*|\/\*[\s\S]*?\*\/)*(['"])use client\1/;const importLine = /^import\s+(?!type\s)(?:[^'"]*?\sfrom\s+)?['"]([^'"]+)['"]/gm;for (const file of files) { const source = readFileSync(join(root, file), "utf8"); if (!prologue.test(source)) continue; const imports = [...source.matchAll(importLine)].map((m) => m[1]); console.log(join(root, file)); console.log(" imports: " + (imports.join(", ") || "(none)"));}
Run it against the four files above and it finds the single entry point:
The script uses the recursive option of readdirSync, so it needs a recent Node release, and it lists direct imports only. For the transitive picture, feed the entry files into a dependency graph as starting nodes; the dependency mapping guide covers building that graph. I treat the output as the first map to build when joining an App Router codebase, alongside the steps in how to understand any codebase.
# Decision table: where should this component live?
When an entry point looks wrong, or a new component lands in review, this is the table I'd put in the team's contributing guide.
The component needs
Put it in
Watch for
Database access, secrets or render-only libraries
A Server Component
Passing whole records or secrets down as props
State, effects, event handlers or browser APIs
The smallest possible "use client" leaf
Everything that file imports
Interactivity around server content (modal, tabs)
A client shell with server content passed as children
Compound components like Tabs.Panel break across the boundary; use named exports
A mutation from a form or button
A Server Function in a "use server" module
Missing validation or authorization inside the function
A third-party component that uses hooks but has no directive
A thin "use client" wrapper file
The wrapper's imports ship with it
React context
A client provider that takes children, rendered as deep as possible
A provider wrapping the whole <html> document
Open, close or submit that the browser already handles
A Server Component using <details> or <form action>
Reaching for useState out of habit
Most rows collapse into one question asked twice: does this need browser state, and if so, can the part that needs it be split into a child?
Figure 2. Most placement decisions come down to two questions: does it need browser state, and can that part become a child?
# The review checklist for a PR that adds "use client"
Is this the smallest file that needs the directive, or could the interactive part move into a child?
What does this file import, and what do those modules import? Anything heavy, or anything that reads the database or environment?
Are the props serializable, and do they carry more data than the UI shows? Every prop ends up in the payload sent to the browser.
Does any module in the new subtree belong on the server only? Then it should import server-only so the build fails loudly.
Is server-rendered content passed in as children rather than imported?
For every new Server Function: input validated, user authorized, used for a mutation rather than for fetching.
To make the boundaries visible to the whole team, draw them. Shade the client subtrees on your architecture diagram (see how to visualize your codebase architecture) and the import graph becomes something people can argue about in a design review.
"use client" marks a module and everything it imports as client code. It's a boundary in the import graph, not a label on one component.
Only two things cross: code through imports, data through serializable props. Server Functions cross as references and need the same validation as any endpoint.
Client Components still render on the server for HTML. The question to ask is whether code ships to the browser.
Map a codebase from its "use client" entry points, then review each one for height, imports and props.
A directive placed too high pulls a whole subtree into the bundle. Move it down to the smallest file that needs browser state.
RSC moved the most important fact about a component, where it runs, out of the component. Put it back where people can see it: in the review checklist and on the map.
Frequently asked questions
What is the difference between Server Components and Client Components?
A Server Component runs only on the server, and its code never reaches the browser. A Client Component renders on the server for the initial HTML and again in the browser during hydration, so its code ships in the client bundle. Which one a component is depends on whether it is imported from a "use client" module.
Does "use server" mark a component as a Server Component?
No. There is no directive for Server Components; they are the default in the App Router. "use server" marks Server Functions, async functions the client can call over the network. Treat their arguments as untrusted input and check authorization inside each one.
Do I need to add "use client" to every interactive component?
No. The directive only needs to be on the entry file of a client subtree. Every module that file imports becomes client code automatically. Adding it everywhere adds noise, and adding it too high in the tree pulls static content into the bundle for no benefit.
When should a component not be a Server Component?
When it needs state, effects, event handlers or browser APIs such as localStorage, or when it uses React context. In those cases make the smallest possible file a Client Component and pass server-rendered content into it as children, so the rest of the tree stays on the server.
No single person can hold a large codebase in their head. A knowledge graph externalizes understanding into a queryable structure. Here's the 4-week playbook to build one.
Choose code search tools for text, symbols and cross-repository exploration. Use ripgrep, GitHub and Sourcegraph queries to find code and related changes.
Apply developer documentation best practices with ADRs, comments and tested examples. Use the WRITE system to keep changes reviewable and find stale guidance.
Compare monorepo vs polyrepo trade-offs for code discovery, ownership and shared contracts. Use practical search and change tasks to assess your own team.