Migrating to Next.js 16 cacheComponents: 5 Things That Actually Broke (Measured in Production)
Real build failures and cache bugs from migrating a DB-backed Next.js blog to cacheComponents — five pitfalls, measured in production.
By Bongyeon Kim · Researched from primary sources, verified by hand, and produced with AI assistance on a production stack this site actually operates (Vercel · Neon · Cloudflare R2).
TL;DR
We moved a database-backed Next.js blog (Neon Postgres, per-slug caching, on-demand revalidation) to cacheComponents with "use cache", and shipped it to production. The migration surfaced five failure modes that cost us real debugging time — and none of them are documented as build-breaking in the places you'd look first. This post is the list we wish existed: what failed, the exact error or behavior, and the working pattern we ship today. Every item below was reproduced on our own deployment, not theorized.
Pitfall 1: unstable_cache and export const revalidate hard-fail at build
The two most commonly cited cache APIs from Next 13–15 era are banned under cacheComponents: true — not deprecated with a warning, but a build failure. Our first migration attempt died on next build with cache-conflict errors on the data gateway file.
The working replacement is the full cache declarative:
// lib/posts.ts — the pattern that survives cacheComponents
export async function getPostBySlugCached(slug: string): Promise<Post | undefined> {
"use cache";
cacheLife({ stale: 2_592_000, revalidate: 2_592_000, expire: 5_184_000 }); // 30d / 60d
cacheTag(`post:${slug}`);
return getPostBySlug(slug);
}
If your mental model is "keep unstable_cache, add "use cache" later" — that path doesn't exist. Grep for both APIs before you start; they must be gone, not migrated in place.
Pitfall 2: segment config exports in dynamic routes fail the build
This one surprised us most because it's encouraged in older docs: exporting dynamicParams or export const revalidate from a dynamic segment breaks the build under cacheComponents. Our /post/[slug] route had export const dynamicParams = true — a harmless-looking default — and the build rejected it.
The lesson: the default behavior is already what you want (dynamicParams = true is the implicit default), so deleting the export is both required and lossless. Audit every page.tsx and route.ts for segment config exports before attempting the migration.
Pitfall 3: revalidateTag needs two arguments now (and only works in the server runtime)
Two separate discoveries merged into one pitfall:
- Signature:
revalidateTag(tag)alone doesn't express our intent — the installed version supportsrevalidateTag(tag, { expire }). For publish-time invalidation we need stale-serving of zero, which isexpire: 0: the next request always regenerates. - Runtime:
revalidateTag()is a server-runtime API. Our publish flow runs from a local script — calling the function directly from Node does nothing useful. The working pattern is a locked-down HTTP endpoint:
// app/api/revalidate/route.ts (secret-checked)
// ?secret=xxx&tag=posts · ?secret=xxx&slug=abc
Check the installed version's .d.ts for the exact signature before assuming — the two-argument form changed how we model expiry (AGENTS.md §4-9 exists precisely because of this one).
Pitfall 4: invalidating data tags isn't enough — route entries survive
The subtlest bug: after revalidating posts and post:${slug}, the prerendered route entry kept serving stale HTML — X-Nextjs-Stale-Time: 30d from the CDN edge. Data-tag invalidation clears the cache layers; the route entry has its own tags (_N_T_/post/...), visible in the route's .meta file, and those must expire too.

Our publish script now performs what we call the two-tap invalidation, plus warm-up:
- Data tap:
revalidateTag('posts', { expire: 0 })+revalidateTag(\post:${slug}`, { expire: 0 })` - Route tap:
revalidateTag('_N_T_/post/${slug}')+revalidatePath('/post/${slug}')— and for static-ish routes like the sitemap, all_N_T_/sitemap.xmltag variants (we found three: base,/route,/layout) - Warm-up: two GETs each for the post and home, because the first request after invalidation can still serve stale
Missing the route tap means readers get old content for up to 30 days while your data layer is fresh. There is no error message for this — it's why we log x-nextjs-cache headers during publish.
Pitfall 5: request-time notFound() becomes a soft-404 under PPR
With Partial Prerendering, the shell commits HTTP 200 before the stream resolves — so calling notFound() during streaming cannot change the status to 404. Next injects <meta name="robots" content="noindex"> instead, which is the documented behavior and fine for SEO over time, but it changes what you can promise.
The pattern we ship:

export default async function PostPage({ params }: PageProps<"/post/[slug]">) {
const { slug } = await params;
const post = await getPostBySlugCached(slug); // cached existence check
if (!post) notFound(); // BEFORE Suspense
return (
<Suspense fallback={<PostShell />}>
<PostContent post={post} /> // verified post as prop
</Suspense>
);
}
Everything after the existence check streams. The component inside Suspense receives the verified post as a prop rather than re-deriving it from params — which also keeps our reads inside the cached gateway.
What we'd tell someone starting the migration
- Order matters: migrate the data gateway first (
"use cache"+cacheLife+cacheTag), routes second, invalidation last. - Test the publish path, not just the read path. All five pitfalls bit hardest after deploy, not at build time — four of five are only visible with a real invalidation cycle.
- Read your route
.metafiles. The_N_T_tags there are the difference between "cache invalid" and "cache invalid and pages actually regenerated." - Verify signatures against your installed version, not against blog posts — including this one. The API surface moved faster than the documentation between releases we've run.
Caveats
All measurements are from one production deployment (Next.js 16, cacheComponents on, Vercel hosting, Neon Postgres) as of 2026-11-27. Where behavior is version-specific we've marked it; the cache-conflict and segment-config build errors are stable across our three iterations of this migration. Related coverage: our on-demand revalidation 404 fix and the ISR safe-net design (30-day stale / 60-day expire) that this migration replaced.