Server & Client Components
Priority: P0 (CRITICAL)
[!WARNING] If the project uses the
pages/directory instead of the App Router, ignore this skill entirely.
Next.js (App Router) uses React Server Components (RSC) by default.
Workflow: Add Server/Client Component Split
- Default to RSC — Write components as async Server Components for data fetching.
- Push
'use client'to leaves — Only add for interactivity (onClick, useState, useEffect). - Compose via children — Pass Server Components as
childrento Client Components. - Serialize props — Ensure all Server-to-Client props are serializable (no functions, Dates, or Classes).
- Guard secrets — Import
server-onlyin modules with sensitive logic.
Composition Pattern Example
Implementation Guidelines
- Async RSCs: Fetch data directly inside async Server Components; use
await db.queries andawait paramsfor route segments. - Data Fetching: Use
fetchwithcache: 'no-store'orrevalidate: 0to opt out of static rendering when needed. - Streaming: Wrap slow async components in
<Suspense>for progressive loading. Useloading.tsxfor route-level skeletons. - Hydration: Server sends HTML + RSC payload; client hydrates only Client Components. Server Components produce zero JS in the client bundle.
- Server-in-Client: You cannot import a Server Component directly into a Client Component.
- Fix: Pass Server Component as
childrenprop to the Client Component. See Composition Example.
- Fix: Pass Server Component as
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 are Client Component-only hooks. - No
'use client'at tree root: Push the boundary to leaf components.