Server & Client Components
Priority: P0 (CRITICAL)
[!WARNING] If project uses
pages/directory instead of App Router, ignore this skill entirely.
App Router uses React Server Components (RSC) by default.
Workflow: Add Server/Client Component Split
- Default to RSC — Async Server Components for data fetching.
- Push
'use client'to leaves — Interactive leaf nodes only (Button, Form, Chart). Keep layouts/pages as Server Components to maximise RSC benefits. - Compose via children — Pass Server Components as
childrento Client Components. - Serialize props — Server-to-Client props must be serializable (no functions, Dates, or Classes).
- Guard secrets — Import
server-onlyin modules with sensitive logic.
Composition Pattern Example
Implementation Guidelines
- Async RSCs: Fetch directly in async Server Components —
await db.queries,await paramsfor route segments. - Data Fetching:
fetchwithcache: 'no-store'orrevalidate: 0opts out of static rendering. - Streaming: Wrap slow async components in
<Suspense>. Useloading.tsxfor route-level skeletons. - Hydration: Server sends HTML + RSC payload; client hydrates only Client Components. Server Components: zero JS in client bundle.
- Server-in-Client: Cannot import Server Component into Client Component.
- Fix: Pass as
childrenprop. See Composition Example.
Anti-Patterns
- No secrets in Client Components: Use
server-onlypackage to prevent accidental bundling. - No full DB objects passed to client: Minimize serialized props; pass IDs when possible.
- No
useState/useEffectin Server Components: These Client Component-only hooks. - No
'use client'at tree root: Push boundary to leaf components.