
cache-components
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). Use when implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, instant navigation validation, 'use cache: private', pass-through/interleaving patterns, GET Route Handler caching, debugging cache issues, and reviewing Cache Component implementations.
- Installs
- 214
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/laguagu/claude-code-nextjs-skills --skill cache-components- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads cache-components automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Cache Components
Keep the project's caching mode unless migration is requested. Confirm the
installed Next.js version and cacheComponents/partialPrefetching configuration before applying
these patterns.
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.
Facts older examples get wrong
- Next.js 16 enables the mode with top-level
cacheComponents: true. It replacesexperimental.dynamicIO,experimental.useCacheandexperimental.ppr;cacheLife/cacheTagimport fromnext/cachewithoutunstable_. In 16.4, setpartialPrefetchingexplicitly: leaving it unset warns; recommendedcreate-next-appdefaults enable both flags. - With it enabled, segment exports
dynamic,revalidate,fetchCacheanddynamicParamsare errors, and Edge runtime is unsupported.revalidate = NbecomescacheLife(nearest or custom profile) insideuse cache;force-dynamicandfetchCacheare unnecessary; fetchnext: { revalidate, tags }becomescacheLife/cacheTagin ause cachefunction; request data goes under Suspense;dynamicParams = falsebecomesnotFound()for unknown params. - Existing
fetchandunstable_cachecaching 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 cacheis in-memory by default; even a durable handler cannot reuse entries when the build/deployment ID changes. generateStaticParamsmust return at least one param:[]fails the build, and removing the export renders the route on every request.revalidate: 0orexpireunder 5 minutes makes a request-time hole instead of prerendered output; of the presets onlysecondsdoes. 16.3 addsstalethresholds (under 30 s: not prerendered; under 5 min: not in the App Shell).- Synchronous
new Date(),Math.random()orcrypto.randomUUID()during prerender is an error: capture it inuse cache, or defer withawait io()(next/cache, 16.3+) orawait connection()(next/server) under Suspense. use cache: privatewas 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_instantin 16.2) opts a segment into instant-navigation validation. Since 16.3, every Page/Default segment is implicitly validated innext devonly (dev overlay) at the default level; build validation requiresexperimental.instantInsights.validationLevelset toexperimental-errororexperimental-manual-error(16.2unstable_instantalso validated at build). Test navigations with@next/playwrightinstant().instant = falsepermits a blocking route; it does not clear synchronous-IO errors.
For whole-app adoption or instant-navigation work, Next.js publishes workflow
skills (next-cache-components-adoption, next-cache-components-optimizer)
in vercel/next.js/skills; the bundled migration guide covers the same steps.
Shape of one route
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>
</>
)
}
Decide the boundary
- Cache reusable results when the product's freshness and data policy permit. Static content needs no directive just to be static.
- A plain
use cachescope cannot read cookies, headers, searchParams or callconnection(), 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, thenext-request-in-use-cacheerror can passnext buildand surface only undernext start. - Keep uncached I/O and request-only content below appropriate Suspense boundaries. Suspense supplies fallback UI; it does not itself make synchronous work dynamic.
- Evaluate private/remote variants against installed docs and deployment handlers. Private caching is not a compliance guarantee; remote caching is not a consistency protocol.
Define freshness and invalidation
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.
Read for the problem
- API boundaries: keys, serialization, lifetimes, handlers and route APIs.
- Composition: tenant isolation, nested caches, pass-through and dynamic params.
- Troubleshooting: diagnose blocking, stale or inconsistent output.
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.
FAQ
What does the cache-components skill do?
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). Use when implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, instant navigation validation, 'use cache: private', pass-through/interleaving patterns, GET Route Handler caching, debugging cache issues, and reviewing Cache Component implementations.
How do I install cache-components?
Run npx skills add https://github.com/laguagu/claude-code-nextjs-skills --skill cache-components in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/cache-components/ (personal) or .claude/skills/cache-components/ (project).
Which AI agents can use cache-components?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is cache-components safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains cache-components?
It is published by laguagu in laguagu/claude-code-nextjs-skills. It has 214 recorded installs.
More from laguagu/claude-code-nextjs-skills
nextjs-seo
laguagu/claude-code-nextjs-skills
Next.js App Router SEO implementation and audits. Use for metadata and social images, sitemap/robots, canonicals and localization, structured data, Core Web Vitals evidence, AI crawler policy or search-indexing diagnosis. Not for general Next.js feature work unrelated to SEO.
openai-agents-sdk
laguagu/claude-code-nextjs-skills
OpenAI Agents SDK (Python) development. Use when building AI agents, multi-agent handoffs, function tools, guardrails, sessions, streaming, or tracing with the openai-agents / agents Python package — including Azure OpenAI through its native client or LiteLLM. Triggers on imports from agents, uses of Runner.runsync/Runner.runstreamed, @functiontool, AgentOutputSchema, SQLiteSession, or questions about the openai-agents-python SDK. Python only — not the TypeScript @openai/agents SDK.
nextjs-shadcn
laguagu/claude-code-nextjs-skills
Builds distinctive Next.js interfaces with shadcn/ui, choosing typography, styling and purposeful visual effects for the product. Use when creating or polishing a Next.js + shadcn app, page or component, including themes, presets, backgrounds and design-system lint. Uses frontend-design for substantial visual direction and icons for asset sourcing.
next-best-practices
laguagu/claude-code-nextjs-skills
Next.js App Router best practices covering file conventions, RSC boundaries, async APIs, data patterns, hydration errors, metadata, route handlers, image/font optimization, and bundling. Use when writing or reviewing Next.js code to prevent hydration errors, RSC violations, data waterfalls, and configuration mistakes.
react-best-practices
laguagu/claude-code-nextjs-skills
React and Next.js performance optimization guide from Vercel Engineering (70 rules in 8 categories). Use when writing, reviewing, or refactoring React/Next.js code to eliminate waterfalls, reduce bundle size, prevent re-renders, optimize Server Components, or fix performance bottlenecks. Triggers on data fetching, Promise.all, Suspense, useMemo, dynamic imports, bundle analysis, code-splitting, and rendering performance tasks.
postgres-semantic-search
laguagu/claude-code-nextjs-skills
Open the skill to read its SKILL.md instructions.
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.