No slash command · from nextjs-plugin
Guides data fetching, caching, and revalidation in Next.js App Router: SSG/ISR/SSR/streaming, fetch caching, unstable_cache, revalidatePath/Tag, Route Handlers, and generateStaticParams.
Ships in nextjs-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Next.js extends fetch() with caching/revalidation primitives, and offers unstable_cache for non-fetch async work. Plus revalidatePath / revalidateTag to invalidate after mutations. Get this layer right and pages become fast and consistent.
Per-route, the decision tree:
| Need | Mode | Setup |
|---|---|---|
| Data unchanged after build (marketing, docs) | SSG (Static) | Default behavior; no special options. |
| Data changes occasionally (hourly/daily) | ISR (revalidate) | fetch(url, { next: { revalidate: 3600 } }) |
| Data per-request (dashboards, account pages) | SSR (Dynamic) | fetch(url, { cache: 'no-store' }) or export const dynamic = 'force-dynamic' |
| Data dynamic but tag-invalidatable | Tagged ISR | fetch(url, { next: { tags: ['users'] } }) + revalidateTag('users') |
| Streaming / progressive | RSC + Suspense | wrap async children in <Suspense fallback={...}> |
By default, Next.js prerenders pages at build time (SSG). Adding cache: 'no-store' or reading dynamic APIs (cookies(), headers(), searchParams) opts the page into SSR.
fetch extensions// SSG: cached forever (default)
const res = await fetch('https://api.example.com/data');
// Static + revalidate every 60s (ISR)
const res = await fetch('https://api.example.com/data', { next: { revalidate: 60 } });
// Always fresh (SSR)
const res = await fetch('https://api.example.com/data', { cache: 'no-store' });
// Tag-based: invalidate manually via revalidateTag
const res = await fetch('https://api.example.com/data', { next: { tags: ['users'] } });
fetch() deduplication: identical fetches within a single render are deduped automatically — call freely from multiple components without worry.
unstable_cache for non-fetch async workWrap any async function with unstable_cache:
import { unstable_cache } from 'next/cache';
import { db } from '@/lib/db';
export const getUsers = unstable_cache(
async () => db.users.findMany(),
['users'], // cache key parts (must be a stable array)
{ revalidate: 60, tags: ['users'] }
);
Use for ORM calls, computed data, anything you'd otherwise duplicate logic to make cacheable.
The cache key parts must be stable strings. To cache PER ARGUMENT, include arguments:
export const getUserById = (id: string) =>
unstable_cache(
async () => db.users.findUnique({ where: { id } }),
['user', id],
{ revalidate: 60, tags: [`user:${id}`] }
)();
Despite the name, unstable_cache is widely used; it's "unstable" by Next's API stability label, not "unreliable."
generateStaticParamsFor dynamic routes that should be statically generated at build:
// app/blog/[slug]/page.tsx
export async function generateStaticParams() {
const posts = await db.post.findMany({ select: { slug: true } });
return posts.map((p) => ({ slug: p.slug }));
}
// dynamicParams (default true) — allow on-demand generation for slugs not pre-built
export const dynamicParams = true;
export default async function PostPage({ params }: { params: { slug: string } }) {
const post = await db.post.findUnique({ where: { slug: params.slug } });
if (!post) notFound();
return <article>{post.content}</article>;
}
Pair with revalidate for ISR — pages are built initially, then refreshed per the schedule.
Per-route configuration via exported constants:
// app/some/page.tsx
export const dynamic = 'auto' | 'force-dynamic' | 'error' | 'force-static';
export const dynamicParams = true | false;
export const revalidate = false | 0 | number;
export const fetchCache = 'auto' | 'default-cache' | 'only-cache' | 'force-cache' | 'force-no-store' | 'default-no-store' | 'only-no-store';
export const runtime = 'nodejs' | 'edge';
export const preferredRegion = 'auto' | 'global' | 'home' | string | string[];
export const maxDuration = number;
Common patterns:
export const dynamic = 'force-dynamic'.export const runtime = 'nodejs' (DB clients usually don't run on edge).app/api/<resource>/route.ts:
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
import { auth } from '@/lib/auth';
// GET /api/users
export async function GET() {
const users = await db.users.findMany();
return NextResponse.json(users);
}
// POST /api/users
const CreateUserSchema = z.object({ email: z.string().email(), name: z.string().min(1) });
export async function POST(req: NextRequest) {
const session = await auth();
if (!session?.user) return NextResponse.json({ error: 'unauthorized' }, { status: 401 });
const body = await req.json();
const parsed = CreateUserSchema.safeParse(body);
if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
const user = await db.users.create({ data: parsed.data });
return NextResponse.json(user, { status: 201 });
}
// app/api/users/[id]/route.ts
export async function GET(_req: NextRequest, { params }: { params: { id: string } }) {
const user = await db.users.findUnique({ where: { id: params.id } });
if (!user) return NextResponse.json({ error: 'not found' }, { status: 404 });
return NextResponse.json(user);
}
export async function DELETE(_req: NextRequest, { params }: { params: { id: string } }) {
await db.users.delete({ where: { id: params.id } });
return new Response(null, { status: 204 });
}
In Next.js 15+, params is a Promise — await params.
Route Handlers are dynamic by default in modern Next.js. To cache GETs:
export const dynamic = 'force-static'; // cache the GET response
export const revalidate = 60;
For most API endpoints, leave dynamic.
// in a Server Action
import { revalidatePath, revalidateTag } from 'next/cache';
export async function deleteUser(id: string) {
'use server';
await db.users.delete({ where: { id } });
revalidatePath('/users'); // path-based — invalidates that route's cache
revalidateTag('users'); // tag-based — invalidates anything fetched with this tag
}
revalidatePath is the simpler tool. revalidateTag is more granular when one resource is fetched in many places.
// app/dashboard/page.tsx
import { Suspense } from 'react';
export default function DashboardPage() {
return (
<>
<h1>Dashboard</h1>
<Suspense fallback={<div>Loading recent activity...</div>}>
<RecentActivity /> {/* async RSC */}
</Suspense>
<Suspense fallback={<div>Loading metrics...</div>}>
<Metrics /> {/* async RSC */}
</Suspense>
</>
);
}
async function RecentActivity() {
const items = await getActivityFromSlowAPI();
return <ul>{items.map(...)}</ul>;
}
The shell renders immediately; each Suspense boundary streams in independently. Combine with loading.tsx for the whole-segment fallback.
export const runtime = 'edge'; // or 'nodejs' (default)
Edge:
fs, no native modules.Default to nodejs unless you have a clear performance reason and your code is edge-compatible.
unstable_cache.cache: 'no-store' everywhere — defeats Next's caching, makes every request hit origin.revalidatePath after a mutation — users see stale data.cookies() / headers() reads in a function intended to be cached — they make the route dynamic.runtime: 'edge' without verifying it's edge-compatible.generateStaticParams returning all DB rows at build for a million-row table — use ISR with a small initial set.searchParams in a Server Component and assuming the page can be static — searchParams force dynamic rendering.NextResponse.json(undefined) — pass null or omit the body.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub aratkruglik/claude-sdlc --plugin nextjs-plugin5 skills in this plugin
/nextjs-conventionsNext.js project structure, App Router conventions, file-based routing primitives, layouts, error boundaries, metadata, image and font optimization, configuration. Apply when implementing or modifying Next.js features.
Use this skill to:
- Pick the correct file convention (page/layout/loading/error/not-found/route/template/default).
- Structure a feature within the App Router tree.
- Set up metadata for SEO and OpenGraph.
- Configure next.config.js for headers, redirects, image domains.
- Use built-in fonts and images correctly.
Do NOT use this skill for:
- Server vs Client component boundaries (see server-component-patterns).
- Data fetching patterns (see nextjs-data-fetching).
- Complex routing (parallel/intercepting routes — see nextjs-routing).
- Testing (see nextjs-testing).
/nextjs-routingNext.js App Router routing primitives: file-based routes, dynamic and catch-all segments, route groups, parallel routes, intercepting routes, middleware, programmatic navigation, link patterns.
Use this skill to:
- Pick the correct dynamic segment syntax for the route shape.
- Use route groups to organize without affecting URLs.
- Implement parallel/intercepting routes for modal-style navigation.
- Build effective middleware for auth, redirects, A/B tests.
- Use Link and useRouter correctly.
Do NOT use this skill for:
- Data fetching per route (see nextjs-data-fetching).
- General file conventions (see nextjs-conventions).
- RSC vs Client (see server-component-patterns).
/nextjs-testingTesting strategies for Next.js: Server Components, Client Components, Server Actions, Route Handlers, end-to-end with Playwright. Vitest/Jest configuration, React Testing Library patterns, msw for network mocks.
Use this skill to:
- Pick the right test layer for what you're testing.
- Configure Vitest or Jest for Next.js.
- Test Server Components without running them in isolation.
- Test Server Actions and Route Handlers as pure functions.
- Set up Playwright for e2e and integration of RSC.
Do NOT use this skill for:
- General Next.js conventions (see nextjs-conventions).
- RSC vs Client model (see server-component-patterns).
- Plain Node.js test patterns (see nodejs-plugin equivalents).
/server-component-patternsReact Server Components vs Client Components in Next.js: the boundary discipline, "use client" / "use server" directives, Server Actions, what serializes across the boundary, common pitfalls.
Use this skill to:
- Decide whether a component should be RSC or Client.
- Push the "use client" boundary as deep as possible.
- Implement Server Actions correctly (auth, validation, revalidation).
- Compose RSC and Client components without breaking the model.
- Pass data across the boundary safely.
Do NOT use this skill for:
- General Next.js conventions (see nextjs-conventions).
- Specific data-fetching APIs and caching (see nextjs-data-fetching).
- Routing (see nextjs-routing).
Other plugins' skills for the same job