Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 09 / Topic 2 of 5

The waterfall, built and measured for real

The naive way to write a page that needs both reviews and stock is to await one, then the other:

// harness/app/mandi/products/[id]/sequential/page.tsx (the async component inside the page)
const reviews = await getReviews(id);
const stock = await getStock(id);

Nothing here looks wrong — it reads top to bottom exactly the way the rest of this course has taught async Server Components to read. But getStock never needed reviews's result, and the code above still makes it wait for it anyway. This is a request waterfall: two independent reads, chained for no reason beyond the order they were typed in.

Hitting this page for real, three times, after a warm-up request (so Turbopack's own first-compile cost doesn't skew the first number):

$ curl -s -o /dev/null "http://localhost:PORT/mandi/products/g2/sequential"   # warm-up, discarded
817 ms
817 ms
827 ms

~820ms, consistently — close to 400ms + 350ms = 750ms plus a little real overhead, exactly what two sequential awaits should cost. The fix is Promise.all, starting both requests before waiting for either:

// harness/app/mandi/products/[id]/page.tsx (the async component inside the page)
const [reviews, stock] = await Promise.all([getReviews(id), getStock(id)]);

The same measurement against this version, same warm-up convention:

458 ms
455 ms
467 ms

~460ms — close to max(400, 350) = 400ms plus overhead, not the sum. The fix cost one word (Promise.all) and saved roughly 45% of the page's load time, measured, not estimated. This is section 2's whole claim, and the two full route files back it: examples/01-product-page-parallel.tsx, examples/02-product-page-sequential.tsx.

🔍 Going deeper — why both versions need <Suspense> at all: This install's cacheComponents: true (on by default, see TOOLING.md) does not allow an await with unpredictable timing directly in a page body during prerendering — the exact same rule Part 5 found for a bare setTimeout-backed promise. Both page.tsx files above wrap their data-reading component in <Suspense>, exactly like Part 7's streaming pages, specifically so next build succeeds at all for a route whose params ARE known (generateStaticParams lists all four ids) but whose data still takes real, variable time. Removing the <Suspense> wrapper and rebuilding reproduces the exact error TOOLING.md already found for new Date():

$ npm run build
...
Error: Route "/mandi/products/g1": Next.js encountered uncached or runtime data during prerendering.
`fetch(...)`, `cookies()`, `headers()`, `params`, `searchParams`, or `connection()` accessed outside of `<Suspense>` prevents the route from being prerendered...

Fetching data correctly (section 2's whole subject) and being allowed to fetch it at all during a build (Part 7's subject) are two separate problems. This part leans on Part 7's answer without re-teaching it.

Done here? The practice set for Part 9 — including the solutions — is on the part page.

Search the guide