next-cache-components-adoption

Migrate a Next.js App Router project to Cache Components and resolve blocking routes.

Updated Dec 17, 2022
One-click install
npx skills add https://github.com/Foodshareclub/foodshare-web --skill next-cache-components-adoption-foodshareclub
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-cache-components-adoption
Source: https://github.com/Foodshareclub/foodshare-web/tree/main/.agents/skills/next-cache-components-adoption
Command: npx skills add https://github.com/Foodshareclub/foodshare-web --skill next-cache-components-adoption-foodshareclub

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Enabling Cache Components in a Next.js app surfaces a flood of blocking-prerender and instant-validation errors across the route tree, and fixing them one by one without a plan stalls the migration. This Skill sequences the entire adoption: flipping the cacheComponents flag, running the cache-components-instant-false codemod, and walking routes feature-by-feature until the build passes. ## Core Features & Use Cases - Strategy selection: Choose between an incremental path (codemod opts every route out first, ship as its own PR) or a direct path (fix routes as the build flags them). - Guided error resolution: Diagnose the three blocker classes — request-time reads (cookies(), headers(), await params), sync-IO calls (new Date(), Math.random()), and "use cache" files reading request data — using the docs page linked from each error. - Runtime verification: Verify each fix in a real browser via the next-dev-loop skill, confirming the static shell renders and <Suspense> fallbacks resolve to real content. - Use Case: You upgrade a Next.js 16.3+ app, set cacheComponents: true, and the build fails on dozens of routes. This Skill runs the codemod, fixes sync-IO blockers in shared layouts, then removes opt-outs one feature at a time until next build is clean. ## Quick Start Enable Cache Components in my Next.js app and work through every blocking route until the build passes.

Frequently Asked Questions about next-cache-components-adoption

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enable Cache Components in a Next.js app?

Set cacheComponents: true in next.config, then run npx @next/codemod@latest cache-components-instant-false ./app to opt every page and layout out of validation. Fix remaining sync-IO blockers the codemod cannot handle, then remove opt-outs feature by feature until the build passes.

How to fix blocking-prerender errors in Next.js Cache Components?

Each blocking error links to a https://nextjs.org/docs/messages/<slug> page with the canonical fix recipe. Common fixes push request-time reads like cookies(), headers(), or awaited params into a <Suspense>-wrapped child component instead of awaiting them at the page top.

Does Cache Components work with the Next.js Pages Router?

No, Cache Components is an App Router feature and the cacheComponents flag does nothing for pages/ routes. A hybrid app works fine: the flag affects app/ routes while pages/ routes are unaffected and need no opt-outs.

Why does my Next.js build fail after enabling cacheComponents?

Builds fail on routes that read request-time data outside <Suspense>, on sync-IO calls like new Date() or Math.random() at render time, and on leftover dynamic, revalidate, or fetchCache exports. The experimental.dynamicIO key also aborts the build and must be removed.

What does export const instant = false do in Next.js?

It marks a route as allowed to block, clearing it in both dev and build validation. On a layout it covers the whole subtree during the build, though client navigations still validate each descendant segment individually.

When should I keep a route blocking instead of fixing it?

Keep instant = false when a route is genuinely per-request with no useful static shell, or when the refactor is too large for now. Confirm with the user and rewrite the TODO comment into a documented reason, since undocumented leftover opt-outs are not acceptable.