Automated migration to Next.js Cache Components #1029
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Your Next.js app has been successfully migrated to Cache Components mode. All routes are working, and all CI validation commands pass.
File: next.config.ts
cacheComponents: trueat root level (required by Next.js 16.0.10)reactStrictMode,serverExternalPackages)File: page.tsx
export const runtime = "nodejs"(default runtime, not needed)File: route.ts
export const runtime = "edge"(incompatible with Cache Components)File: layout.tsx
Suspenseboundary aroundThemeProvidernext-themesuses client-side APIs that need Suspensenullfor seamless loadingFile: Header.tsx
Suspenseboundary around navigation linksNavLinkcomponent usesusePathname()(dynamic API)File: src/app/[...parts]/page.tsx
"use cache: private"directiveBuild Status:
Route Status:
/- Partial Prerender (static shell with dynamic content)/[...parts]- Partial Prerender with private cache/about- Static/about/api- Static (revalidate: 30m, expire: 1y)/api/-/versions- Dynamic/api/[...parts]- DynamicCI Validation:
✅ Lint: Passed
✅ Tests: 10 suites, 98 tests - all passed
✅ TypeCheck: Passed
✅ Build: Passed (no errors)
Routes are dynamic by default
Opt-in to caching with
"use cache"or"use cache: private"Clear boundaries between static and dynamic content
Static shells load instantly
Dynamic content streams in via Suspense boundaries
Better perceived performance
The
/[...parts]route can be prefetched with actual runtime valuesInstant navigation between package diffs
No loading states for prefetched routes
Clear error messages during build
Explicit Suspense boundaries for dynamic APIs
Better control over caching behavior
1. Main Diff Page (
/[...parts]):"use cache: private"for runtime prefetching2. Layout Components:
ThemeProviderwrapped in Suspense (client-side theme detection)usePathname()is dynamic)3. API Routes:
Add Cache Tags for granular revalidation: ```typescript import { cacheTag } from "next/cache";
// In a component/function with "use cache" cacheTag("package-diff"); ```
Configure Cache Lifetimes for time-based revalidation: ```typescript import { cacheLife } from "next/cache";
// In a component/function with "use cache" cacheLife("hours"); // or 'minutes', 'days', 'weeks', 'max' ```
Consider Edge Runtime for API routes:
/api/-/versionsTest in Development:
bash pnpm run devTest in Production:
bash pnpm run build && pnpm run startMonitor Performance:
All changes include descriptive comments:
"use cache: private")Your Next.js app is now fully migrated to Cache Components! 🎉
The migration enables better caching control, partial prerendering, and runtime prefetching while maintaining all existing functionality. All CI checks pass, and the app is ready for deployment.
Closes #1026