{"name":"configure-nextjs-server-components","description":"Uses current Next.js routing as intended - Server Components by default, a small client boundary, streaming with Suspense, and Server Actions for mutations. Use when the user asks about server versus client components, server actions, streaming, or a route segment.","category":"frontend","tags":["nextjs","server-components"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/configure-nextjs-server-components","api_url":"https://theskillvault.ai/api/skills/configure-nextjs-server-components","raw_url":"https://theskillvault.ai/api/skills/configure-nextjs-server-components/raw","body":"# Configure Next.js server components\n\nRoute files are Server Components unless you opt into the browser. Put `\"use client\"` on the smallest interactive leaf, not on the layout.\n\n## When to use\n- A whole page is marked `\"use client\"` and the bundle is mostly JavaScript.\n- A form should submit on the server without a hand-written API route.\n- A heavy section blocks the rest of the page instead of streaming in.\n\n## When not to use\n- You still need to create the project, add a CSS framework and push the first commit. That is a setup task.\n- The build fails with a type or import error. Fix the build first.\n- You want to host the site. Hosting is a separate step.\n\n## Steps\n1. Keep `page.tsx` and `layout.tsx` as Server Components. Fetch data there with `async` and `await`.\n2. Add `\"use client\"` only on the leaf that needs state, effects or browser events. Pass it plain props, not functions from the server and not secrets.\n3. From Next.js 15 onward, `fetch` is not cached unless you say so. Set `cache: \"force-cache\"` or a revalidate time only for data that can be shared. On older Next 14, the default was the opposite, so check the version before you copy a snippet.\n4. Wrap a heavy child in `<Suspense fallback={...}>` and add `loading.tsx` for the route. The rest of the page can paint first.\n5. Add `error.tsx` so a thrown error shows a message instead of a blank screen. It must be a client component. The framework already insists on that.\n6. For a mutation, prefer a Server Action in a file that starts with `\"use server\"`. Check the session, validate the input, then write. Return a small result the form can show.\n7. Read dynamic data (cookies, headers, a search param) only in the route that needs it, so the static parts of the layout stay static.\n\n```tsx\nasync function storeName(formData: FormData) {\n  \"use server\";\n  const name = String(formData.get(\"name\") ?? \"\").trim();\n  if (!name) return { error: \"Name is missing\" };\n  await db.user.update({ name });\n  return { ok: true };\n}\n```\n\n## Gotchas\n- A secret, database URL or service token in a client component is sent to the browser. Keep it in the server action or a route handler.\n- Importing a client component into a server file is allowed. Importing a server component into a client file is not. Pass the server tree as `children` instead.\n- Server Actions are public endpoints. Check auth on every call. Do not trust a hidden field for the user id.\n- `cookies()` and `headers()` opt the route into dynamic rendering. Do not call them in a layout that should stay static.\n\n## Portability\nThis is specific to Next.js server components and server actions. If you use Remix or SvelteKit, the same split applies: load data on the server, keep the interactive leaf small, and validate every mutation. The file names differ.\n\n## Done when\n- Pages and layouts are server components, and `\"use client\"` is only on interactive leaves.\n- A heavy block streams behind Suspense instead of blocking the page.\n- Mutations check auth and validate input on the server, and no secret reaches the client bundle.\n\n## Example prompt\n\"This dashboard page is all use client. Move the data fetch to a Server Component and leave only the filter buttons on the client.\"\n\n---\nAdapted from the Next.js router-patterns skill in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.","files":["LICENSE.txt"],"license":"MIT","license_name":"MIT License","license_url":"https://opensource.org/license/mit","attribution":"Based on work by Seth Hobson (wshobson/agents, nextjs-app-router-patterns) (Copyright (c) 2024 Seth Hobson, MIT License), https://github.com/wshobson/agents/tree/7e2fb559cf4b824b27f1fec49fe88f7511066d26/plugins/frontend-mobile-development/skills/nextjs-app-router-patterns; adapted by TheSkillVault, https://theskillvault.ai","install":{"claude_code":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-nextjs-server-components/raw' -o ~/'.claude/skills/configure-nextjs-server-components/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-nextjs-server-components/files/LICENSE.txt' -o ~/'.claude/skills/configure-nextjs-server-components/LICENSE.txt'","cursor":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-nextjs-server-components/raw' -o '.cursor/skills/configure-nextjs-server-components/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-nextjs-server-components/files/LICENSE.txt' -o '.cursor/skills/configure-nextjs-server-components/LICENSE.txt'","agents":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-nextjs-server-components/raw' -o '.agents/skills/configure-nextjs-server-components/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/configure-nextjs-server-components/files/LICENSE.txt' -o '.agents/skills/configure-nextjs-server-components/LICENSE.txt'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-29T03:42:30.374Z"}}