Skillshub nextjs-server-components
RSC usage, ''use client'' directive, and Component Purity. Use when working with React Server Components or deciding where to place the ''use client'' boundary. (triggers: app/**/*.tsx, src/app/**/*.tsx, app/**/*.jsx, src/app/**/*.jsx, use client, Server Component, Client Component, hydration)
git clone https://github.com/ComeOnOliver/skillshub
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/nextjs-server-components" ~/.claude/skills/comeonoliver-skillshub-nextjs-server-components && rm -rf "$T"
skills/HoangNguyen0403/agent-skills-standard/nextjs-server-components/SKILL.mdServer & Client Components
Priority: P0 (CRITICAL)
[!WARNING] If the project uses the
directory instead of the App Router, ignore this skill entirely.pages/
Next.js (App Router) uses React Server Components (RSC) by default.
Implementation Guidelines
-
Next.js Default: Use React Server Components (RSC) for 90% of your UI. Leverage
for direct data fetching.async components -
Client Boundary: Only use the
directive for interactivity (e.g.,'use client'
), hooks (onClick
,useState
), or browser APIs. Place the boundary at the leaf nodes to maximise RSC benefits and server-side rendering.useEffect -
Composition: Use
to pass Server Components as<ClientWrapper><ServerDataComponent /></ClientWrapper>
to Client Components. Avoid Circular Dependencies between server and client. Direct database access:children
queries inside async RSCs, andawait db.
before accessing route segments.await params -
Data Fetching: Use
withfetch
orcache: 'no-store'
to opt out of static rendering when needed.revalidate: 0 -
Loading & UI: Use
triggers around slow async components to enable Streaming and better UX. UseSuspense
for route-level loading states.loading.tsx -
Serialization: Ensure all props passed from Server to Client are Serializable (No functions, Dates, or Classes).
-
Security: Never share secrets or server-only logic within Client Components. Use
package to enforce this.server-only -
Hydration: Server sends HTML + RSC payload (JSON); client hydrates only Client Components. Server Components produce zero JS in the client bundle — no useState/useEffect shipped to browser.
-
Server-in-Client: You cannot import a Server Component directly into a Client Component.
- Fix: Pass Server Component as
prop to the Client Component. See Composition Example.children
- Fix: Pass Server Component as
Anti-Patterns
- No secrets in Client Components: Use
package to prevent accidental bundling.server-only - No full DB objects passed to client: Minimize serialized props; pass IDs when possible.
- No
/useState
in Server Components: These are Client Component-only hooks.useEffect - No
at tree root: Push the boundary to leaf components.'use client'