Per-request nondeterministic output
A Server Component needs a different random value for each request without reading cookies or headers.
Next.js 16+ · Function
connection() makes rendering wait for a real incoming request before continuing. Use it when per-request output is needed but the component does not use request-time APIs such as cookies or headers.
Call connection() in an async Server Component when rendering must wait for an incoming request even though the code does not use request-time APIs. Everything after the await is excluded from prerendering and runs for each request; the returned promise is only used for synchronization.
function connection(): Promise<void>Promise<void>
import { connection } from 'next/server'
export default async function Page() {
await connection()
const value = Math.random()
return <p>{value}</p>
}Waits for a real request before generating a per-request random value.
A Server Component needs a different random value for each request without reading cookies or headers.
A synchronous database driver query should run during the request rather than during prerendering.
A runtime environment variable must be read per request instead of being captured during the build.
connection() has no parameters and returns a Promise<void>. Awaiting it tells Next.js to wait for an incoming request, so work after the call is excluded from prerendering.
Follow-up: When is it unnecessary? It is unnecessary if the component already uses request-time APIs such as cookies or headers, because those APIs already require dynamic rendering.
Use it when output varies per request without using request-time APIs, such as output based on Math.random() or new Date(). Place it before the request-dependent operation.
Follow-up: What happens to the surrounding UI? The request-bound component can stream from the nearest Suspense boundary while the static shell remains prerendered.
connection() replaced unstable_noStore and was introduced as a request-bound rendering API. It became stable in Next.js 15.0.0.
Follow-up: What should be preferred with Cache Components? Prefer io() for excluding content from the static shell because it can also be cached and prefetched.
Request-time APIscookiesheadersunstable_noStoreio()Cache ComponentsSuspense