Request-time rendering
What you need to know
connection() from next/server lets server code wait for an incoming request before continuing. Use it when the intended result depends on request-time execution even if no other request API is read, such as a server timestamp. It is a rendering boundary, not an authentication method or a universal cache purge.
By the end, you can: choose request-dependent boundaries; avoid accidental public caching.
app/clock/page.tsx
import { connection } from "next/server";export default async function Clock() { await connection(); const instant = new Date().toISOString(); return <main><h1>Request clock</h1><time dateTime={instant}>{instant}</time></main>;}Expected behavior (not framework-tested): The time is evaluated after a request. Validate that the ISO value falls inside the request interval, allowing for clock resolution; do not assert that two fast requests must differ.
How it works
In the disabled Cache Components lane, cookies and headers already indicate request-dependent work. connection is useful if there is no such API and the code still must execute after a request. Await it before the operation that must not be performed during prerendering. A dynamic route can still fetch public data from a persistent cache if configured. With Cache Components enabled, runtime work generally needs a suitable Suspense boundary and explicit cached scopes for static portions; do not reuse disabled-lane segment configuration unchanged. Private responses require data-level authorization and carefully scoped cache policy, including any external reverse proxy or CDN.
A request-dependent page with a public read (partial page)
import { cookies } from "next/headers";import { listPublicBooks } from "../../lib/dal";export default async function Shelf() { const view = (await cookies()).get("view")?.value === "compact" ? "compact" : "comfortable"; const books = await listPublicBooks(); return <main><h1>Public shelf</h1><p>{view}</p><p>{books.length} titles</p></main>;}Expected behavior (not framework-tested): Different preferences can produce different page output while the public catalog source is shared conceptually. This direct read is not itself a configured persistent cache.
Common mistake
Do not use connection to claim that all fetches are fresh or that CDN caching is disabled. A request-time decision does not invalidate previously cached data. Do not place user-specific values in shared public cache entries. Inspect production response headers and separate browser contexts when validating privacy.
Practice and verification
Compare /help, /clock and /preferences in a production run. For /clock test an ISO timestamp range; for /preferences test distinct cookie contexts. Add a hypothetical cached public-data read and describe which observation would prove that it was reused.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.
Further reading: Connection · Cookies · Fetch · Cache Migration · Data Security