/nextjs-ai-skills:cache-componentsfrom nextjs-ai-skills
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). Covers 'use cache' directive, cacheLife(), cacheTag(), revalidation, static/dynamic boundaries, and debugging cache issues.
Ships in nextjs-ai-skills. 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.
Read when SKILL.md points to them.
Keep the project's caching mode unless migration is requested. Confirm the
installed Next.js version and cacheComponents/partialPrefetching configuration before applying
these patterns. Use Cache Components on next 16.4.5+: 16.0.0–16.4.0 allow
unauthenticated RCE through use cache functions returning typed arrays
(GHSA-673q-mjm6-r5xr; no workaround, upgrade even without such functions), and
releases through 16.4.4 can leak or poison cached output across users
(GHSA-rhh4-g77r-r9qj binary arguments, GHSA-vvgp-ww4w-46vf shared fallback
shells, GHSA-vc7v-qv4w-wrv8 and GHSA-mfr8-8qww-v76h root params).
Flag an affected install before cache work.
Read the relevant guide in node_modules/next/dist/docs/ first (bundled since
16.2; in a monorepo, use the app's own next package). Web paths map to files
with numbered folders, so find them by name: .../functions/cacheLife is
01-app/03-api-reference/04-functions/cacheLife.md. Under 01-app/, start
with 02-guides/migrating-to-cache-components.md,
01-getting-started/08-caching.md and 02-guides/instant-navigation.md.
Error pages under /docs/messages are not bundled; next dev/next build
print the fix options inline. Without local docs, use the
official caching docs.
Exact exports and signatures are also in node_modules/next/cache.d.ts.
For static-output and staged-deferral questions in 16.4+, find the installed
ensureStatic route-segment reference and navigation/prefetch function
references by name.
The goal is a useful prerendered shell with freshness and authorization rules that remain correct after mutations, deploys and client navigation.
cacheComponents: true. It replaces
experimental.dynamicIO, experimental.useCache and experimental.ppr;
cacheLife/cacheTag import from next/cache without unstable_.
In 16.4, set partialPrefetching explicitly: leaving it unset warns;
recommended create-next-app defaults enable both flags.dynamic, revalidate, fetchCache,
dynamicParams and runtime (even 'nodejs') are errors; only the default
Node.js runtime is supported. revalidate = N
becomes cacheLife (nearest or custom profile) inside use cache;
force-dynamic and fetchCache are unnecessary; fetch
next: { revalidate, tags } becomes cacheLife/cacheTag in a use cache
function; request data goes under Suspense; dynamicParams = false becomes
notFound() for unknown params.fetch and unstable_cache caching still works as a separate layer,
so do not mechanically rewrite every read. Its persistence across deployments
and instances depends on retained/shared storage; self-hosted instances do not
share it by default. use cache is in-memory by default; even a durable
handler cannot reuse entries when the build/deployment ID changes.generateStaticParams must return at least one param: [] fails the build,
and removing the export renders the route on every request.revalidate: 0 or expire under 5 minutes makes a request-time hole instead
of prerendered output; of the presets only seconds does. 16.3 adds stale
thresholds (under 30 s: not prerendered; under 5 min: not in the App Shell).new Date(), Math.random() or crypto.randomUUID() during
prerender is an error: capture it in use cache, or defer with await io()
(next/cache, 16.3+) or await connection() (next/server) under Suspense.use cache: private was experimental through 16.2. It runs at request time,
stays out of the static shell and accepts no custom handler.export const instant (16.3; unstable_instant in 16.2) opts a segment into
instant-navigation validation. Since 16.3, every Page/Default segment is
implicitly validated in next dev only (dev overlay) at the default level;
build validation requires experimental.instantInsights.validationLevel
set to experimental-error or experimental-manual-error (16.2
unstable_instant also validated at build). Test navigations with
@next/playwright instant(). instant = false permits a blocking route;
it does not clear synchronous-IO errors.For whole-app adoption of Cache Components or Partial Prefetching, use the
official workflow skills listed in the installed 01-app/02-guides/ai-agents.md
(from vercel/next.js skills/); the bundled 02-guides/migrating-to-cache-components.md
and adopting-partial-prefetching.md cover the same steps.
app/posts/page.tsx, checked against next 16.3.8 with cacheComponents: true
(tsc --noEmit, next build, the action under next start). @/lib/* is
project code.
import { Suspense } from 'react'
import { cookies } from 'next/headers'
import { cacheLife, cacheTag, updateTag } from 'next/cache'
import { insertPost, listPosts } from '@/lib/posts' // project code
import { requireEditor } from '@/lib/auth' // throws unless the session may edit
async function getPosts() {
'use cache' // shared entry: no cookies/headers/searchParams inside
cacheLife('hours')
cacheTag('posts')
return listPosts()
}
async function Theme() {
const theme = (await cookies()).get('theme')?.value // request-time, outside the cache
return <p>Theme: {theme ?? 'system'}</p>
}
async function addPost(formData: FormData) {
'use server'
await requireEditor()
const title = String(formData.get('title') ?? '').trim()
if (!title) return
await insertPost(title)
updateTag('posts') // Server Actions only; the next read waits for fresh data
}
export default async function Page() {
const posts = await getPosts() // cached, so it can be part of the static shell
return (
<>
<ul>{posts.map((p) => <li key={p.id}>{p.title}</li>)}</ul>
<Suspense fallback={<p>Theme: …</p>}><Theme /></Suspense>
<form action={addPost}><input name="title" /><button>Add</button></form>
</>
)
}
use cache scope cannot read cookies, headers, searchParams or call
connection(), including indirectly through helpers. Read those outside
and pass authorized, serializable values.
Account/tenant IDs must participate in the cache key when output depends on them.
On a dynamically rendered route, the next-request-in-use-cache error can
pass next build and surface only under next start.Choose lifetimes from actual acceptable staleness. Named profiles can be overridden by the project; read its config before assuming a duration.
Use tags when invalidation must reach the same entity across routes, path invalidation for route-specific output, or expiry where that meets the contract. Authenticate, authorize and validate before mutations. Invalidate only affected cached data:
updateTag: immediate expiry/read-your-writes, Server Actions only.revalidateTag(tag, 'max'): stale-while-revalidate on a later visit.revalidateTag(tag, { expire: 0 }): immediate expiry where a webhook/Route
Handler needs it. The one-argument form is deprecated.These tag APIs can also apply to tagged fetch data; their availability does not by itself mean Cache Components is enabled.
Run the production build, then exercise cold/direct navigation, client
navigation, the relevant mutation and subsequent read under next start.
Check tenant isolation and multi-instance invalidation when applicable.
A passing build cannot establish those behaviors.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub laguagu/claude-code-nextjs-skills --plugin nextjs-ai-skills24 skills in this plugin
/agent-harness-reviewReviews an agent harness or agent design against Anthropic's agent and model prompting guidance (Opus 5.5, Fable 5.2), Cognition's context principles and 2026 research on skill routing and skill-induced failures. Covers when subagents or parallel agents pay off, how to brief them, how many skills, plugins, MCP servers and hooks load every session, tool design and proportionate verification. Use when auditing a Claude Code or Codex setup, deciding whether to add subagents or a multi-agent workflow, trimming a skill library, or designing an agent loop in an app. For writing a new skill or measuring a skill's trigger rate with evals, use skill-creator./ai-appBuilds full-stack Next.js AI applications with the AI SDK and the shadcn/ui AI Elements patterns. Use when creating a chatbot, agent dashboard or custom AI application./ai-elementsMaintains AI chat UI built from elements.ai-sdk.dev AI Elements components already copied into the project. Use when changing or debugging those components (conversations, messages, prompt inputs, attachments, reasoning, tool output, sources). New chat UI uses the shadcn/ui AI Elements patterns (`shadcn` skill)./ai-sdkAnswer questions about the AI SDK and help build AI-powered features. Use when developers ask about Vercel AI SDK, generateText, streamText, ToolLoopAgent, useChat, AI SDK providers, tools, structured output, embeddings or streaming, or want to add AI features to a TypeScript or JavaScript app. First identify the installed major version and route version-specific work: use ai-sdk-7 for AI SDK 7 features/migrations such as WorkflowAgent, HarnessAgent, reasoning, runtime/tools context, toolApproval, telemetry, realtime, or v6-to-v7 upgrades; for v6 code read the docs shipped in the installed package./ai-sdk-6Vercel AI SDK v6 development, for projects already on ai@6. Use when building or maintaining AI agents, chatbots, tool integrations, streaming apps, or structured output in a v6 codebase. New projects and ai@7 code use ai-sdk-7; an unknown version goes through ai-sdk. Covers ToolLoopAgent, useChat, generateText, streamText, tool approval, provider tools, MCP integration, and Output patterns./ai-sdk-7Vercel AI SDK v7 development and migration. Use when building or upgrading AI SDK 7 apps, especially ToolLoopAgent, WorkflowAgent, HarnessAgent, Claude Code/Codex/Pi harnesses, runtimeContext, toolsContext, toolApproval, telemetry, reasoning, file or skill uploads, realtime, video generation, or v6-to-v7 breaking changes. For version discovery, v6 code and general doc lookup use ai-sdk.Other plugins' skills for the same job