Static vs dynamic rendering
Every route segment is either static — prerendered at build time — or dynamic — rendered on each request. What decides it is the data the segment reads.
Runtime APIs need information that only exists when a request arrives:
cookies(), headers(), searchParams, and dynamic params. A component that
reads them cannot finish during prerendering, so its work happens at request time:
async function UserGreeting() {
const theme = (await cookies()).get('theme')?.value ?? 'light';
return <p>Your theme: {theme}</p>;
}
Wrap such a component in <Suspense> so the shell still prerenders and the
runtime read streams in. With Cache Components, reading cookies() no longer opts
the whole route into dynamic rendering — the rest of the page stays static.
You can override the decision with the route segment config:
export const dynamic = 'force-static'; // prerender regardless
export const dynamic = 'force-dynamic'; // render every request
force-static is useful when a runtime API's value does not matter at build time;
force-dynamic when the route must always be fresh. Leave it unset and Next.js
infers the mode from the APIs the segment uses. Without a <Suspense> boundary, a
runtime access surfaces a blocking-route insight in the dev overlay.
You are about to answer a short quiz on static vs dynamic rendering.