Lesson 2 of 9 · 26m
Server and Client Component Boundaries
Where to place "use client", which props can cross the boundary, and how composition keeps browser JavaScript small without giving up interactivity.
Most App Router bugs are boundary bugs. The error text mentions serialization, hooks, or undefined props, but the underlying mistake is always the same: something crossed the server-client line in a shape it cannot cross.
The boundary is a module boundary, not a runtime annotation sprinkled over arbitrary functions. Once a file starts with "use client", everything it imports becomes part of the client graph unless explicitly loaded through a server boundary or dynamic import. That transitive behavior is why one small directive near the route root quietly swallows the application.
Put the directive at the interactive leaf
// app/reports/page.tsx — server component
import { ReportTable } from "./report-table";
import { DownloadButton } from "./download-button";
export default async function ReportsPage() {
const rows = await getReports();
return (
<>
<ReportTable rows={rows} />
<DownloadButton reportId="monthly" />
</>
);
}ReportTable stays server-rendered. useState stays in the leaf. This is the shape you want.
Props must be serializable
A server component can pass strings, numbers, booleans, arrays, plain objects, null, and React elements through supported composition. It cannot pass event handlers, database clients, ORM entities with hidden methods, Map in older runtimes, or arbitrary class instances.
// wrong: the function cannot cross the boundary
<ClientPanel onLoad={loadRows} />
// right: load on the server, pass data down
const rows = await loadRows();
<ClientPanel initialRows={rows} />For mutations, do not pass a callback down. Use a server action reference, covered later.
Composition is the escape hatch
You cannot import server components into client components directly, but you can pass them as props:
// page.tsx
<ClientSidebar>
<ServerUserSummary />
</ClientSidebar>This keeps ServerUserSummary out of the client bundle even though it visually lives inside client-managed chrome. Use children or named slots before reaching for state duplication.
Environment leakage is real
Server components can read process.env.DATABASE_URL; client components cannot unless you deliberately expose NEXT_PUBLIC_ variables. Treat NEXT_PUBLIC_ as publishing the value to the internet. It is not a configuration namespace — it is a public distribution mechanism.
Field notes
error.tsxand global error boundaries must be client components because they need reset interactions.- Do not pass ORM models to the client. Map them into plain DTOs near the query layer.
Was this lesson helpful?