Frontend · Skill
Configure Next.js server components
configure-nextjs-server-components
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.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
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 (this project)
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'Codex and other Agent Skills tools (this project)
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'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}Route files are Server Components unless you opt into the browser. Put "use client" on the smallest interactive leaf, not on the layout.
When to use
- A whole page is marked
"use client"and the bundle is mostly JavaScript. - A form should submit on the server without a hand-written API route.
- A heavy section blocks the rest of the page instead of streaming in.
When not to use
- You still need to create the project, add a CSS framework and push the first commit. That is a setup task.
- The build fails with a type or import error. Fix the build first.
- You want to host the site. Hosting is a separate step.
Steps
- Keep
page.tsxandlayout.tsxas Server Components. Fetch data there withasyncandawait. - 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. - From Next.js 15 onward,
fetchis not cached unless you say so. Setcache: "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. - Wrap a heavy child in
<Suspense fallback={...}>and addloading.tsxfor the route. The rest of the page can paint first. - Add
error.tsxso a thrown error shows a message instead of a blank screen. It must be a client component. The framework already insists on that. - 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. - Read dynamic data (cookies, headers, a search param) only in the route that needs it, so the static parts of the layout stay static.
async function storeName(formData: FormData) {
"use server";
const name = String(formData.get("name") ?? "").trim();
if (!name) return { error: "Name is missing" };
await db.user.update({ name });
return { ok: true };
}
Gotchas
- 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.
- 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
childreninstead. - Server Actions are public endpoints. Check auth on every call. Do not trust a hidden field for the user id.
cookies()andheaders()opt the route into dynamic rendering. Do not call them in a layout that should stay static.
Portability
This 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.
Done when
- Pages and layouts are server components, and
"use client"is only on interactive leaves. - A heavy block streams behind Suspense instead of blocking the page.
- Mutations check auth and validate input on the server, and no secret reaches the client bundle.
Example prompt
"This dashboard page is all use client. Move the data fetch to a Server Component and leave only the filter buttons on the client."
---
Adapted from the Next.js router-patterns skill in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.
Bundled files
Licence
Adapted from Seth Hobson (wshobson/agents, nextjs-app-router-patterns) (Copyright (c) 2024 Seth Hobson), MIT License. Adapted by TheSkillVault: rewritten as a short checklist for current Next (server by default, explicit cache, server actions); dropped the file-tree catalogue; added secret rules, gotchas and done-when.
Licence: MIT License. Attribution when you reuse it: 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