One page reads cookies() inside <Suspense> and the other reads nothing. Is each route static or dynamic?
The tea shop's home page lists its teas. Its cart page counts the teas in the visitor's cart cookie. The app is new, so Cache Components is on, as create-next-app sets it up. What does next build print for each page in its route table?
app/layout.tsximport Link from "next/link";
export const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>
<nav>
<Link href="/">Teas</Link> <Link href="/cart">Cart</Link>
</nav>
{children}
</body>
</html>
);
}
app/page.tsxconst teas = ["Green tea", "Mint tea", "Oolong tea"];
export default function Home() {
return (
<main>
<h1>Our teas</h1>
<ul>
{teas.map((tea) => (
<li key={tea}>{tea}</li>
))}
</ul>
</main>
);
}
app/cart/page.tsximport { Suspense } from "react";
import { cookies } from "next/headers";
async function CartCount() {
const cart = (await cookies()).get("cart")?.value ?? "";
const count = cart ? cart.split(",").length : 0;
return <p>{count} teas in your cart</p>;
}
export default function CartPage() {
return (
<main>
<h1>Your cart</h1>
<Suspense fallback={<p>Counting your teas…</p>}>
<CartCount />
</Suspense>
</main>
);
}
It's a project create-next-app made (Next.js 16.4.3, TypeScript, the App Router, and Cache Components on) with these files, built with next build. What happens:
- You run
next build.
The answer
Work out what Next.js does at each step: what the build prints, what each request answers, and what the page shows. Then check.
Checking your sign-in…