
On this page
If you turned on Cache Components in Next.js 16 and next build stopped with this error, the fix is usually one <Suspense> boundary. The hard part is finding *where* it goes, because the stack trace can point at a file that has nothing to do with the problem.
I reproduced the error on this site (Next.js 16.4.6, cacheComponents: true) with a test page, then tried each fix Next.js suggests and checked what the build output said. Everything below comes from those builds.
The full error
Error: Route "/zz-uncached": Next.js encountered uncached or runtime data during prerendering.
`fetch(...)`, `cookies()`, `headers()`, `params`, `searchParams`, or `connection()` accessed outside of `<Suspense>` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
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
Learn more: https://nextjs.org/docs/messages/blocking-prerender-dynamicDepending on what your code reads, you may see a shorter variant of the same error: "encountered uncached data during prerendering" (for fetch() or connection()) or "encountered runtime data during prerendering" (for cookies(), headers(), params or searchParams). The cause and the fixes are the same.
What the error means
With Cache Components on, Next.js tries to prerender a static shell for every route at build time. Anything that can only be known at request time has to be marked, so Next.js knows where the static part ends. It accepts two kinds of markers:
- A
<Suspense>boundary around the part that needs request data. Everything outside it goes into the static shell; the inside streams in on each request. "use cache"on the function that fetches the data. The result is computed once and can be part of the static shell.
The error means a request-time read (fetch, a database call, cookies(), headers(), params, searchParams or connection()) ran with neither marker around it, so Next.js can't decide what belongs in the shell.
Reproducing it
This page is enough to trigger it. connection() tells Next.js "render this at request time", and nothing wraps it in Suspense:
import { connection } from "next/server";
export default async function Page() {
await connection();
return <p>Rendered at request time</p>;
}Why the stack trace points at the wrong file
This surprised me. The code frame under the error did not show my page. It showed the motion provider in the root layout:
at <unknown> (src\components\providers\MotionProvider.tsx:14:34)
at body (<anonymous>)
at html (<anonymous>)
> 14 | export function MotionProvider({ children }: { children: React.ReactNode }) {That file has no data access at all. It's just the nearest component above the page that wraps children. So don't trust the code frame. Use these instead:
- The route name in the first line (
Route "/zz-uncached"). That is the page to look at. next dev: open that route in the browser. The dev overlay shows the error with a more useful stack.next build --debug-prerender: Next.js itself suggests this flag at the bottom of the error for better stack traces.- Search the route's files for the six reads listed in the message:
fetch(,cookies(,headers(,params,searchParams,connection(. Don't forget database clients and SDK calls, which usefetchunder the hood.
Fix 1: wrap the request-time part in Suspense (best default)
Move the data access into its own component and wrap that component in <Suspense>. The rest of the page stays static:
import { Suspense } from "react";
import { connection } from "next/server";
async function RequestTime() {
await connection();
return <p>Rendered at request time</p>;
}
export default function Page() {
return (
<>
<h1>Static shell</h1>
<Suspense fallback={<p>Loading…</p>}>
<RequestTime />
</Suspense>
</>
);
}The build passed and listed the route as ◐ (Partial Prerender): the heading is static HTML, and only the inner part renders per request. Keep the boundary as low as you can. A Suspense around the whole page also passes the build, but then nothing is in the shell.
Fix 2: cache the data with "use cache"
If the data is the same for every visitor (a product list, a CMS page, blog posts), you don't need request-time rendering at all. Cache the function that loads it:
import { cacheLife } from "next/cache";
async function getProducts() {
"use cache";
cacheLife("hours");
const res = await fetch("https://api.example.com/products");
return res.json();
}
export default async function Page() {
const products = await getProducts();
return <ProductList products={products} />;
}In my test build, a page whose only request-time work sat inside a "use cache" function (with no Suspense) built as ○ (Static). Two limits: "use cache" does not work for connection(), and it can't wrap cookies() or headers(), because those are per request by definition. Read them outside the cached function and pass the values in as arguments, or use Fix 1.
Fix 3: export const instant = false (last resort)
import { connection } from "next/server";
export const instant = false;
export default async function Page() {
await connection();
return <p>Rendered at request time</p>;
}This also made the build pass, but the route became ƒ (Dynamic): no static shell, the whole page renders on each request. instant = false tells Next.js the route is allowed to block. Use it for pages that truly can't show anything before the data arrives, or as a temporary switch while you migrate. For everything else, Fix 1 or 2 gives a faster page.
Which fix to pick
| Your data | Fix | Build result in my test |
|---|---|---|
| Same for every visitor (CMS, products, posts) | "use cache" + cacheLife() | ○ Static |
| Per visitor or per request (cookies, auth, search params) | <Suspense> around that part | ◐ Partial Prerender |
| The page can't show anything without the data | export const instant = false | ƒ Dynamic |
Checklist
- Read the route name in the error, not the code frame.
- Find the request-time read:
fetch, database/SDK calls,cookies(),headers(),params,searchParams,connection(). - Shared data: cache it with
"use cache". Per-request data: wrap the smallest possible component in<Suspense>. - Remember
loading.tsxcounts as a Suspense boundary for everything below it. - Run
next buildagain and check the route symbol:○or◐means the page still has a static shell.
Hitting the new Date() version of this error instead? That one has its own fixes: Fix "unstable value new Date() while prerendering". For every other change I made when turning Cache Components on, see my migration notes.
Frequently asked questions
What does "Next.js encountered uncached or runtime data during prerendering" mean?
With Cache Components on, Next.js prerenders a static shell for each route. The error means a request-time read (fetch, a database call, cookies(), headers(), params, searchParams or connection()) ran outside a Suspense boundary and outside a "use cache" function, so Next.js can't decide what belongs in the static shell.
Why does the stack trace point to a provider or layout file?
The code frame can show the nearest component that wraps children, such as a provider in the root layout, instead of the page that made the read. Use the route name in the first line of the error, open that route in next dev, or rerun the build with next build --debug-prerender.
Does loading.tsx fix this error?
Often, yes. loading.tsx creates a Suspense boundary for everything below it, so request-time reads in those pages are already inside Suspense. Routes outside that folder don't get the boundary.
Can I use "use cache" with cookies() or connection()?
No. "use cache" does not apply to connection(), and cookies() and headers() are per request. Read them outside the cached function and pass the values in as arguments, or wrap the component in Suspense.
- Next.js 16
- Cache Components
- Suspense
- Errors
Keep reading
FoodHub · Restaurant ordering & delivery · Australia
FoodHub: Building a White-Label Restaurant Ordering SaaS
A white-label SaaS for an Australian founder that lets any restaurant launch its own commission-free ordering and delivery website, with live rider tracking and Stripe Connect payouts. Built solo, end to end.
- Live on the platform
- 2 restaurants
- Storefront, admin console, API
- 3 apps

React & Next.js6 min read
Fix: "Next.js encountered the unstable value new Date() while prerendering"
Why Next.js 16 fails the build on new Date(), Date.now() or Math.random() with Cache Components, why "use client" alone doesn't fix it, and which of the fixes to use for your case.

React & Next.js7 min read
Next.js 16 Cache Components: What Broke When I Turned It On (and the Fixes)
I enabled Cache Components on this site, a Next.js 16 portfolio with a blog and case studies. Here is every error and surprise I hit, why it happens, and the exact code that fixed it.
