What makes a route dynamic in the App Router?
A route (or, with Cache Components, a part of it) becomes dynamic when it needs information only available at request time: cookies(), headers(), searchParams, connection(), draftMode() in some cases, uncached data access, or unprerendered dynamic params.
Request-time triggers
- Runtime APIs:
cookies(),headers(), thesearchParamsprop, and reading request properties in a Route Handler. connection(): explicitly waits for a real request.- Uncached I/O: a
fetchwithout caching, database queries, async file reads. - Non-deterministic values:
Math.random(),Date.now(),crypto.randomUUID(). With Cache Components you must choose: cache them with"use cache"or defer withawait connection()orawait io(). - Dynamic params not returned by
generateStaticParams.
Previous model (no Cache Components)
Any trigger made the entire route dynamic. You could also force it with export const dynamic = 'force-dynamic', revalidate = 0, or fetch(url, { cache: 'no-store' }). useSearchParams in a Client Component without a <Suspense> boundary made the page client-render up to the nearest boundary.
With Cache Components
Only the component that uses the trigger is dynamic. Next.js requires it to be inside <Suspense> (or cached), and the rest of the route stays in the static shell. Options like dynamic, revalidate, fetchCache and runtime are not used with Cache Components.
Tip
Push request-time reads as deep in the tree as possible. Pass the params or searchParams promise down instead of awaiting it at the top of a layout, so more of the page is prerendered.
Code example
1// app/dashboard/page.tsx2import { Suspense } from "react";3import { cookies, headers } from "next/headers";4import { connection } from "next/server";56async function Greeting() {7 const name = (await cookies()).get("name")?.value; // dynamic trigger8 return <p>Hi {name ?? "there"}</p>;9}1011async function Geo() {12 const country = (await headers()).get("x-vercel-ip-country"); // dynamic trigger13 return <p>Shipping to {country}</p>;14}1516async function RequestId() {17 await connection(); // dynamic without reading request data18 return <p>Request {crypto.randomUUID()}</p>;19}2021export default function Page() {22 return (23 <main>24 <h1>Dashboard</h1> {/* static shell */}25 <Suspense fallback={<p>…</p>}>26 <Greeting />27 <Geo />28 <RequestId />29 </Suspense>30 </main>31 );32}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.