With Cache Components on, Next.js 16 treats data as dynamic until you say otherwise, and next build stops when you forget to choose. That's useful once you know what each error wants.
I built a small notes app on a fresh create-next-app and hit each error below on purpose. Every snippet was built with next build and run with next start; the form was tested with Playwright. Versions: Next.js 16.4.6, React 19.3.0, Node 22.
1. Check that Cache Components is on
A fresh create-next-app (16.4.6) generated a next.config.ts with both flags already set:
// next.config.ts import type { NextConfig } from "next"; const nextConfig: NextConfig = { cacheComponents: true, partialPrefetching: true, }; export default nextConfig; The build log confirms it with - Cache Components enabled. On an older project, add both flags yourself. The cacheComponents docs say to set partialPrefetching explicitly, because leaving it unset logs a warning.
Two limits from the docs: Cache Components needs the Node.js runtime (remove any export const runtime), and use cache isn't supported with static export.
2. The first error: uncached data outside <Suspense>
A JSON file stands in for the database here:
// lib/db.ts import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; const file = path.join(process.cwd(), "data", "notes.json"); export async function readNotes(): Promise<string[]> { return JSON.parse(await readFile(file, "utf8")); } export async function writeNotes(notes: string[]) { await writeFile(file, JSON.stringify(notes)); } A page that awaits readNotes() directly fails the build:
Error: Route "/": Next.js encountered uncached or runtime data during prerendering. Ways to fix this: - [stream] Provide a placeholder with `<Suspense fallback={...}>` around the data access - [cache] For uncached data (`fetch`, database calls): cache the access with `"use cache"` (does not apply to `connection()`) - [block] Set `export const instant = false` to allow a blocking route For a notes list that changes a few times a day, [cache] is the right pick.
3. Cache the read with "use cache"
// lib/notes.ts import { cacheLife, cacheTag } from "next/cache"; import { readNotes } from "@/lib/db"; export async function getNotes() { "use cache"; cacheLife("hours"); cacheTag("notes"); const notes = await readNotes(); return { notes, cachedAt: new Date().toISOString() }; } // app/page.tsx import { getNotes } from "@/lib/notes"; import { addNote } from "./actions"; export default async function Page() { const { notes, cachedAt } = await getNotes(); return ( <main> <p>Cached at {cachedAt}</p> <ul> {notes.map((n) => ( <li key={n}>{n}</li> ))} </ul> <form action={addNote}> <input name="text" aria-label="New note" /> <button>Add</button> </form> </main> ); } The build now passes, and the route table shows the hours profile:
Route (app) Revalidate Expire ┌ ○ / 1h 1d └ ƒ /api/revalidate Two requests to / on next start returned the same cachedAt. Per the use cache docs, the cache key includes the build ID and the function's arguments, and both arguments and return values must be serializable.
4. Pick a cacheLife profile
The presets, from the cacheLife docs:
| Profile | stale | revalidate | expire |
|---|---|---|---|
default | 5 min | 15 min | never |
seconds | 30 s | 1 s | 1 min |
minutes | 5 min | 1 min | 1 hour |
hours | 5 min | 1 hour | 1 day |
days | 5 min | 1 day | 1 week |
weeks | 5 min | 1 week | 30 days |
max | 5 min | 30 days | 1 year |
stale is how long the client router reuses data without asking the server, revalidate is when the server refreshes in the background, and expire is how long an entry can go without traffic before the next request has to wait for fresh content.
One catch: an expire under 5 minutes is left out of the prerender. seconds is the only preset that crosses that line, so this page fails with the same "uncached or runtime data" error as section 2, even though it uses "use cache":
// app/live/page.tsx import { cacheLife } from "next/cache"; async function LivePrice() { "use cache"; cacheLife("seconds"); return <p>Price checked at {new Date().toISOString()}</p>; } export default function Page() { return <LivePrice />; } Wrap it in <Suspense> (imported from react) and the route becomes a partial prerender:
export default function Page() { return ( <main> <h1>Live price</h1> <Suspense fallback={<p>Loading price…</p>}> <LivePrice /> </Suspense> </main> ); } └ ◐ /live ◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content 5. Nested caches need their own cacheLife
Put that short-lived component inside another cached component with no cacheLife, and the build stops:
Error: Route "/dashboard": A nested `"use cache"` with a short `expire` (under 5 minutes) is inside an outer `"use cache"` that has no `cacheLife()`. Add `cacheLife()` to the outer one to choose whether to prerender it with a longer `expire` or keep it dynamic with a short `expire`. Adding cacheLife("hours") to the outer component fixes the error, but the docs say an explicit outer lifetime wins, so a price rendered inside it would be cached for an hour too. To keep the price live, pass it in as children. Slots pass through a cached component without becoming part of its entry:
// app/dashboard/page.tsx (LivePrice is the same as above) import { Suspense, type ReactNode } from "react"; import { cacheLife } from "next/cache"; async function Dashboard({ children }: { children: ReactNode }) { "use cache"; cacheLife("hours"); return ( <section> <h2>Dashboard, cached at {new Date().toISOString()}</h2> {children} </section> ); } export default function Page() { return ( <Dashboard> <Suspense fallback={<p>Loading price…</p>}> <LivePrice /> </Suspense> </Dashboard> ); } Three requests, three seconds apart: the heading kept its build-time timestamp, and the price showed a new time on each request.
6. updateTag in a Server Action: show users their own change
// app/actions.ts "use server"; import { updateTag } from "next/cache"; import { readNotes, writeNotes } from "@/lib/db"; export async function addNote(formData: FormData) { const text = String(formData.get("text") ?? "").trim(); if (!text) return; await writeNotes([...(await readNotes()), text]); updateTag("notes"); } In Playwright, I typed a note and clicked Add. The new note appeared right after the click, and cachedAt changed. updateTag expires the tag right away, so the next read waits for fresh data. It only works inside Server Actions.
7. revalidateTag from a Route Handler: stale-while-revalidate
For a CMS webhook, use revalidateTag. In Next.js 16 it takes a second argument. The old one-argument call fails type checking:
app/api/revalidate/route.ts(8,3): error TS2554: Expected 2 arguments, but got 1. // app/api/revalidate/route.ts import { revalidateTag } from "next/cache"; export async function POST(request: Request) { if (request.headers.get("x-revalidate-secret") !== process.env.REVALIDATE_SECRET) { return Response.json({ ok: false }, { status: 401 }); } revalidateTag("notes", "max"); return Response.json({ ok: true }); } What I saw on next start:
- Edited
notes.jsonby hand:/still showed the old list. -
POST /api/revalidatewithout the header:401. With it:200. - First request after that: still the old list.
- Next request: the edited list.
That's the "max" profile at work: the first visitor after the call gets the stale page while Next.js refreshes it in the background. Use updateTag when the user who made the change must see it right away, and revalidateTag(tag, "max") when a short delay is fine.
8. Don't read cookies() inside "use cache"
Error: Route "/greeting": `cookies()` can't be read inside `"use cache"`. Read it outside the cached function and pass what you need as an argument. The message tells you the fix. Read the cookie in an uncached component and pass the value in:
// app/greeting/page.tsx import { Suspense } from "react"; import { cookies } from "next/headers"; import { cacheLife } from "next/cache"; async function Greeting({ name }: { name: string }) { "use cache"; cacheLife("hours"); return <p>Hi, {name}</p>; } async function GreetingFromCookie() { const name = (await cookies()).get("name")?.value ?? "friend"; return <Greeting name={name} />; } export default function Page() { return ( <Suspense fallback={<p>Loading…</p>}> <GreetingFromCookie /> </Suspense> ); } With Cookie: name=Abu the page said "Hi, Abu", and without it "Hi, friend". Each name gets its own cache entry because name is an argument.
Wrapping up
- Fresh 16.4.6 projects ship with
cacheComponents: true. Expect the "uncached or runtime data" error and pick[cache]or[stream]. - Call
cacheLifein every"use cache"scope.secondsneeds a<Suspense>boundary. - Give an outer cache its own
cacheLife, and pass live parts in aschildren. -
updateTagfor a user's own writes,revalidateTag(tag, "max")for webhooks. - Read
cookies()andheaders()outside the cache and pass values in.
One limit: I tested on a single next start process. The docs note that on serverless hosts the default in-memory cache may not be reused between requests, so check what your host does.
Which of these errors did you hit first when you turned on Cache Components?
I keep checks like these as free, MIT-licensed agent skills for Next.js launches: npx skills add nandot12/nextjs-launch-skills · GitHub


