React Server Components 29 🧬 Cheatsheet
This cheatsheet covers the RSC model as it exists across Next.js, Waku, and custom bundler setups. It is scoped to what you do, not to what exists. The directives, the boundary rules, the security constraints, the testing split, and the performance measurements are the things you reach for mid-build. Each section is a decision, not a directory.
The Three Directives
| Directive | Where | Effect |
|---|---|---|
'use client' | Top of file | Marks the client boundary; the module and its imports enter the client bundle |
'use server' | Top of file or async function | Marks a Server Function; callable from the client as a reference |
'use cache' | Top of async function or component | Caches the result (Cache Components) |
Source:
Server vs Client: the only decision that matters
| If the component… | Directive | Why |
|---|---|---|
Fetches data with await | none (Server) | Async only works on the server |
Uses useState, useEffect, onClick | 'use client' | Hooks and events are browser-only |
Reads cookies() or headers() | none (Server) | Request APIs are server-only |
| Receives data as props from a Server Component | 'use client' if interactive, none if not | Let the parent fetch |
| Wraps server content | 'use client' with children | The children stay server-rendered |
The Transitivity Rule
The 'use client' boundary is transitive. A module marked with the directive and everything it imports become client code. The size of the client bundle is the size of the subtree beneath each directive, not the number of directives.
| Placement | Client bundle |
|---|---|
| Layout or page | Entire subtree |
| Section wrapper | The section subtree |
| Interactive leaf | The leaf and its imports |
| Server Component | Zero (code runs on server) |
Server Functions: the security checklist
| Check | Where | Why |
|---|---|---|
| Authenticate the session | Inside the function | It is a public endpoint |
| Authorize the operation | Inside the function | The UI guard is not a security control |
| Validate input | Inside the function | Client arguments are untrusted |
| Return only needed fields | The return statement | Return values are serialized to the client |
Never accept a userId from a form field. Derive it from the session.
Source:
Props: the serialization boundary
| Pattern | Safe? | Why |
|---|---|---|
<Client user={user} /> | ❌ | Full object, every field serialized |
<Client name={user.name} /> | ✅ | Only the field the client needs |
<Client formatter={fn} /> | ❌ | Functions are not serializable |
<Client action={serverAction} /> | ✅ | Server Function references are serializable |
The rule: pass only the fields the Client Component actually renders. A prop the client does not use is still serialized.
Source:
Secret hygiene
| Guard | Scope | What it prevents |
|---|---|---|
import 'server-only' | The module | The module entering the client graph |
experimental_taintUniqueValue | The specific value | The value crossing the boundary |
| DTO in the data access layer | The data access layer | The full record leaving the server |
NEXT_PUBLIC_ prefix | The variable | A server variable reaching the client |
import 'server-only' is per-file. A sibling file without it is not protected.
Source:
Third-party wrappers
| Library type | Wrapper needed | Pattern |
|---|---|---|
| Charts (Recharts) | Yes | Re-export with 'use client' |
| Animation (Framer Motion) | Yes | Adapter wrapper |
| UI (MUI interactive) | Yes | Re-export per component |
| Provider (next-themes) | Yes | Wrapper with children |
Libraries shipping 'use client' | No | Import directly |
The wrapper goes at the leaf, not the root. Props must be serializable.
Testing split
| Component type | Unit test (Vitest) | E2E test (Playwright) |
|---|---|---|
| Synchronous Server Component | Yes | Optional |
| Async Server Component | No | Yes |
| Client Component | Yes | Optional |
| Server Action | No | Yes |
The async keyword is the boundary. Vitest’s render() receives a Promise, not a component.
Source:
Performance measurements
| Metric | Tool | Unit |
|---|---|---|
| Client bundle | next experimental-analyze | Bytes |
| RSC payload | curl -H "RSC: 1" / network ?_rsc= | Bytes |
| Hydration time | Performance trace / Lighthouse TBT/INP | Milliseconds |
| Boundary budget | rsc-contract | Bytes (estimated) |
The RSC payload and the client bundle are different measurements. A smaller bundle does not guarantee a smaller payload.
The four migration patterns
| Pattern | Before | After |
|---|---|---|
| Data-fetching component | useEffect + fetch | async Server Component |
| Interactive leaf | Client Component with data fetching | Client Component with props |
| Provider wrapper | Client Component wrapping everything | Client Component with children |
| Composition slot | Client Component importing server content | Client Component with children |
The order is leaf-first: data-fetching components, then interactive components, then routes, then mutations.
Framework support reality
| Framework | RSC status | Production readiness |
|---|---|---|
| Next.js App Router | Stable | Production-ready |
| Waku | 1.0 alpha | Not recommended |
| React Router v7 | In development | Not recommended |
| Custom bundler | Possible | Requires building a framework |
RSC cannot run standalone. The framework provides the bundler, the server, and the router.
Source:
The one-line summary
Server by default. Cache explicitly. Auth every action. Narrow every prop.
Server Components are the starting point. 'use cache' is how you opt into caching. Every Server Function re-validates the session because it is a public endpoint. Every prop is narrowed to the fields the client renders because the boundary is serialization, not privacy.
Summary
| Area | Key takeaway |
|---|---|
| Directives | 'use client', 'use server', 'use cache' |
| Boundary | Transitive; place it at the leaf |
| Server Functions | Public endpoints; authenticate and authorize inside |
| Props | Serialized; pass only what the client renders |
| Secrets | server-only per module; taint values |
| Third-party | Wrapper with 'use client' at the leaf |
| Testing | Vitest for sync, Playwright for async |
| Performance | Bundle and payload are separate measurements |
| Migration | Leaf-first, four patterns, one route at a time |
| Framework | RSC is not standalone; the framework is the runtime |
Remember: The 'use client' directive is a boundary, and the boundary is transitive. The 'use server' directive is a public endpoint, and the endpoint is untrusted. The props are serialized, and serialization is publication. The framework is the runtime, and the runtime is not optional. The cheatsheet is the set of decisions, and the decisions are the discipline.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!