Rendering Strategies and Streaming
Next.js decides per route (previous model) or per component (Cache Components) what is prerendered at build time and what renders at request time, then streams the result through Suspense boundaries.
Key points
- 1
Without Cache Components, one request-time API (
cookies(),headers(),searchParams,draftMode()) or uncached fetch makes the whole route dynamic (ƒ); segment config likedynamic,revalidateanddynamicParamstunes this. - 2
With
cacheComponents: true, Partial Prerendering is the default: static markup,'use cache'results and Suspense fallbacks form a static shell (◐), and runtime or uncached parts stream in.dynamic,revalidate,fetchCacheanddynamicParamsare removed. - 3
<Suspense>gives a fallback but does not make work dynamic. Useawait connection()for per-request values such asMath.random()or synchronous DB reads. - 4
ISR serves the stale page after the window and regenerates in the background. The lowest
revalidatein the route wins, ano-storeorrevalidate: 0fetch makes it dynamic, and failed regenerations keep the last good page. - 5
Once streaming starts, the status (200) and headers are fixed: mid-stream
notFound()adds anoindexmeta tag andredirect()becomes client-side. Check existence before any Suspense boundary for a real 404. - 6
Client Components are prerendered to HTML and hydrated. Locale and time formatting cause hydration mismatches; fix them with an inline script plus
suppressHydrationWarningon each corrected element. - 7
HTML-limited bots skip the shell and get a full request-time render, so anything the shell needs must also exist at request time.
Common traps
Returning
[]fromgenerateStaticParamsmeans "render on first visit" without Cache Components, but it is a build error with Cache Components (return at least one param).loading.jsdoes not wrap its own segment'slayout.js,template.jsorerror.js, so a slow layout is not covered by its own loading UI.next/dynamicwithssr: falseonly works inside a Client Component, andruntime = 'edge'is deprecated and unsupported with Cache Components.
Test yourself on Rendering Strategies and Streaming
Ten questions, with the answer and explanation after each one.