Part 08 / Stage 2
Next.js's rendering philosophy
Goal: Stop thinking of "static" and "dynamic" as a route-level either/or. Next.js draws that line at the component level, and this part proves it with a real IRCTC-style PNR status checker — build a diagrammed trace of exactly which parts of two real pages are static, which are dynamic, and why, backed by the build output and the actual bytes Next.js wrote to disk. Time: ~5 h · Level: 🟡 finished Part 7 (streaming and Suspense) Verified against: Next.js 16.4.6, this course's harness (
cacheComponents: true,partialPrefetching: true— Part 1, section 8)
What you will learn
- Why Next.js treats static vs dynamic as a spectrum inside one page, not a choice made once per route
- The three dynamic APIs that force request-time work —
cookies(),headers(),searchParams— andparams, which behaves differently depending ongenerateStaticParams - How to read every symbol a
next buildroute table can show (○,◐,ƒ) and what each one is actually claiming - The real, current status of Partial Prerendering in this installed version — verified against the package on disk, not assumed from memory
- That
generateStaticParamsand"use cache"are two separate decisions, not one — and what happens when you make only the first - A concrete rule for when to reach for static, cached, or fully dynamic rendering
Topics in this part
Practice
Every exercise below modifies a scratch copy of app/status/ or a throwaway sibling route, runs a real command, and then restores the harness to the exact state Part 8's README ends on: generateStaticParams listing only 2458001234 and 2458005678, lookupPnr with no "use cache". Copy the exact commands you ran and their real output into your own notes; do not type output from memory.
Exercise 1: Promote the unlisted PNR
Scenario: Confirm for yourself that adding a param to generateStaticParams only ever grows the shell, never bakes in the Suspense-wrapped data on its own.
What to do: Add { pnr: "2458009999" } to generateStaticParams in a scratch copy of app/status/[pnr]/page.tsx. Run next build and check both the route table symbol and the actual prerendered HTML for that id.
Sample output (run for real against this course's harness):
$ npm run build
...
├ ◐ /status/2458001234
├ ◐ /status/2458005678
└ ◐ /status/2458009999
$ python3 -c "print('Duronto' in open('.next/server/app/status/2458009999.html').read())"
False
💡 Hint: Still ◐, still no train name baked in — section 3's point made with a third id instead of the two the README used.
Exercise 2: Confirm the unknown-PNR status code for yourself
Scenario: Don't take section 3's 200/noindex claim on faith.
What to do: Visit any PNR not in lib/pnr.ts's records object (e.g. /status/1111111111) against a running production build, and check both the HTTP status and the response body.
Sample output (run for real against this course's harness):
$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost:PORT/status/1111111111
200
$ curl -s http://localhost:PORT/status/1111111111 | grep -o 'noindex'
noindex
💡 Hint: This is the same mechanism Part 7 section 7 demonstrated for a thrown error — once the shell streams with its 200, that status is locked in, notFound() or not.
Exercise 3: Trigger the blocking-prerender error with a different API
Scenario: Section 3's error came from an un-Suspense'd async read. Reproduce the same error class using headers() instead, to confirm it isn't specific to one API.
What to do: In a scratch page, call await headers() directly in the page's default export (no <Suspense> anywhere), then build.
Sample output (run for real against this course's harness):
$ npm run build
...
Error: Route "/scratch-headers-demo": 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, blocking the page load and leading to a slower user experience.
💡 Hint: Identical error text to Part 7 section 3's cookies() version, confirming the error message's own list — fetch, cookies(), headers(), params, searchParams, connection() — really is one unified rule, not six separate ones.
Exercise 4: Watch AppRoutes pick up /status
Scenario: Part 2 section 9 read the generated AppRoutes type once. Confirm this part's two new routes appear in it the same way.
What to do: grep harness/.next/types/routes.d.ts for the AppRoutes type after building.
Sample output (run for real against this course's harness):
$ grep "^type AppRoutes" harness/.next/types/routes.d.ts
type AppRoutes = "/" | "/ops" | "/ops/orders" | "/status" | "/status/[pnr]" | ...
💡 Hint: /status/[pnr] shows the literal bracket syntax, exactly like /store/products/[id] did in Part 2 — route groups are invisible here, dynamic segments are not.
Exercise 5: Reproduce the PPR deprecation finding yourself
Scenario: Section 6 asserted experimental.ppr is deprecated in this installed version. Confirm it against the files on your own machine, not this README's copy.
What to do: Run the two grep commands from section 6 against your own harness/node_modules/next.
Sample output (run for real against this course's harness — reproduce it, don't retype it):
$ grep -n -B4 "ppr?: boolean" harness/node_modules/next/dist/server/config-shared.d.ts
/**
* @deprecated This configuration option has been merged into `cacheComponents`.
* The Partial Prerendering feature is still available via `cacheComponents`.
*/
ppr?: boolean | 'incremental';
💡 Hint: If a future Next.js major version changes this, your own grep output is the only thing you should trust — not this README, and not your memory of this lesson.
Exercise 6: Build your own trace table for a different page
Scenario: Apply section 3-5's method to a page this part didn't already analyze for you.
What to do: Pick app/ops/page.tsx (Part 7) and build a trace table like examples/04-rendering-trace.md's, labeling each region (the <h1>, the summary paragraph, LiveDelayedOrders, NearbyPartners) as static shell or streamed-uncached, with your own evidence (build symbol, a curl, or a byte check of the prerendered HTML).
Sample output (run for real against this course's harness, one row of evidence):
$ python3 -c "print('ORD-4821' in open('harness/.next/server/app/ops.html').read())"
False
💡 Hint: getTodaysSummary() has no await at all — it belongs in a different row of your table than the two Suspense-wrapped components, even though all three live in the same file.
Exercise 7: Flip the gap yourself
Scenario: Section 5 showed the "use cache" proof already applied. Reproduce it with your own hands, on a different function.
What to do: Add "use cache" and cacheLife("hours") to getNearbyPartnerCount in app/ops/lib/delay.ts (a scratch copy). Rebuild and check whether /ops's symbol or its prerendered HTML content changes.
Sample output (run for real against this course's harness):
$ npm run build
...
├ ◐ /ops
$ python3 -c "print('partners online' in open('.next/server/app/ops.html').read())"
True
💡 Hint: /ops stays ◐ overall (LiveDelayedOrders is still uncached), but the specific section you cached now bakes its result into the shell — the route-level symbol and a single function's cache status are two different granularities, exactly like section 5's generateStaticParams-vs-"use cache" split, just measured a different way.
Exercise 8 (stretch): Find every (varies) claim this part makes, and say why
Scenario: This course's own verification standard marks non-deterministic output (varies). Audit this part's README for every place that applies.
What to do: Re-read Part 8's README and list each value that would differ on a different machine or run (port numbers, millisecond timings, the digest hash) versus each value that would not (route table symbols, HTTP status codes, header names, the literal deprecation text).
💡 Hint: This isn't a code exercise — it's the habit this entire course is trying to build. If you can't tell which category a number in your own notes falls into, you probably copied it without running it yourself.
Show the solutions for Part 8 (8 files)
solutions/ex01.md
# Solution to Exercise 1: promote the unlisted PNR
Add the third record to `generateStaticParams` in a scratch copy of `app/status/[pnr]/page.tsx`:
```ts
export function generateStaticParams() {
return [{ pnr: "2458001234" }, { pnr: "2458005678" }, { pnr: "2458009999" }];
}
```
Real build, run against this course's harness:
```text
$ npm run build
...
├ /status/[pnr]
│ ├ ◐ /status/[pnr]
│ ├ ◐ /status/2458001234
│ ├ ◐ /status/2458005678
│ └ ◐ /status/2458009999
```
Still `◐` for all three — promoting a param into `generateStaticParams` only changes whether a shell is pre-generated for that exact URL at build time, it doesn't retroactively cache the Suspense-wrapped `lookupPnr` call inside it:
```text
$ python3 -c "print('Duronto' in open('.next/server/app/status/2458009999.html').read())"
False
```
`"Duronto"` (the train name for this PNR) is still absent from the prerendered HTML — exactly the same result section 3 found for the two originally-listed PNRs. Revert `generateStaticParams` back to two entries afterward.
solutions/ex02.md
# Solution to Exercise 2: confirm the unknown-PNR status code for yourself
Pick any PNR that doesn't exist in `app/status/lib/pnr.ts`'s `records` object — `1111111111` is used here, deliberately different from the README's own `0000000000`, to prove the behavior isn't specific to one magic value:
```text
$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost:PORT/status/1111111111
200
$ curl -s http://localhost:PORT/status/1111111111 | grep -o "noindex"
noindex
```
`200`, not `404` — confirmed against this course's harness, for a PNR this README never mentioned by number. `PnrDetails` calls `notFound()` once `lookupPnr` resolves to `null`, but by that point in the response the static shell (with its `200` status) has already started streaming — the same constraint Part 7 section 7 demonstrated for a thrown error, and the installed package's own streaming guide states directly: *"Once streaming begins, the HTTP response headers (including the status code) have already been sent to the client. You cannot change the status code... after streaming starts."*
The `<meta name="robots" content="noindex">` tag is Next.js's compensating mechanism — search engines still get told not to index the page, even though the transport-level status says `200`.
solutions/ex03.md
# Solution to Exercise 3: the same build error from a different API
A scratch route with `headers()` read directly in the page body, no `<Suspense>` anywhere:
```tsx
// app/scratch-headers-demo/page.tsx
import { headers } from "next/headers";
export default async function ScratchHeadersDemoPage() {
const h = await headers();
return <p>{h.get("user-agent") ?? "unknown"}</p>;
}
```
Real error, run against this course's harness:
```text
$ npm run build
...
Error: Route "/scratch-headers-demo": 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, blocking the page load and leading to a slower user experience.
Ways to fix this:
- [stream] Provide a placeholder with `<Suspense fallback={...}>` around the data access
- [cache] For uncached data (`fetch`, database calls): cache the access with `"use cache"` (does not apply to `connection()`)
- [block] Set `export const instant = false` to allow a blocking route
```
Byte-for-byte the same error text Part 7 section 3 produced using `cookies()` with no Suspense boundary — only the route name in the first line differs. The error message's own list (`fetch`, `cookies()`, `headers()`, `params`, `searchParams`, `connection()`) is accurate: this is genuinely one rule covering six different triggers, not six separate error paths that happen to read the same. Delete `app/scratch-headers-demo/` afterward.
solutions/ex04.md
# Solution to Exercise 4: watching `AppRoutes` pick up `/status`
```text
$ grep "^type AppRoutes" harness/.next/types/routes.d.ts
type AppRoutes = "/" | "/ops" | "/ops/orders" | "/status" | "/status/[pnr]" | "/store" | "/store/about" | "/store/contact" | "/store/go/[id]" | "/store/products" | "/store/products/[id]" | "/store/quick-add/[id]" | "/store/search/[...terms]" | "/store/wholesale"
```
(The exact list beyond `/ops`, `/ops/orders`, `/status`, and `/status/[pnr]` is `(varies)` — it reflects whatever other parts of this course have been built into the shared harness at the moment you run this, not just Parts 7–8.)
`/status/[pnr]` appears with the literal `[pnr]` bracket syntax, exactly the way `/store/products/[id]` did when Part 2 section 9 first ran this same grep. Two facts confirmed again, now against a route this part built itself rather than one the README already analyzed: dynamic segments show their bracket syntax literally in this generated type, and there is still no separate entry for any route group (this part didn't use one, but the principle — "this type reports back the folder tree you built, nothing more" — is Part 2's finding, reproduced here on new routes, not a new fact).
solutions/ex05.md
# Solution to Exercise 5: reproduce the PPR deprecation finding yourself
Run the exact two commands section 6 names, against your own installed package:
```text
$ grep -n -B4 "ppr?: boolean" harness/node_modules/next/dist/server/config-shared.d.ts
1047: /**
1048: * @deprecated This configuration option has been merged into `cacheComponents`.
1049: * The Partial Prerendering feature is still available via `cacheComponents`.
1050: */
1051: ppr?: boolean | 'incremental';
```
```text
$ grep -n "^## \`experimental_ppr\`" harness/node_modules/next/dist/docs/01-app/02-guides/migrating-to-cache-components.md
946:## `experimental_ppr`
$ sed -n '946,948p' harness/node_modules/next/dist/docs/01-app/02-guides/migrating-to-cache-components.md
## `experimental_ppr`
**Removed. Enable `cacheComponents` instead.** Next.js 16 removes the experimental Partial Prerendering flag (`experimental.ppr`) and the `experimental_ppr` route segment config. Partial Prerendering is now part of [Cache Components](/docs/app/api-reference/config/next-config-js/cacheComponents), so remove `experimental.ppr` from `next.config` and `experimental_ppr` from your segments.
```
Both reproduce exactly. The line numbers themselves (`1047`, `946`) are `(varies)` — they belong to this exact `16.4.6` install and will shift in a different version or even a different patch release. What should **not** vary, and is the actual point of this exercise: the `@deprecated` JSDoc tag on the `ppr` field, and the "Removed. Enable `cacheComponents` instead." sentence, state the same fact two different ways in two different files that ship with the package itself — not a blog post, not a tutorial, the files `next` actually runs. Any future version that changes this story again will change these exact files, which is why section 6 ends with "re-run the two `grep`/`sed` commands above against whatever version is actually installed" rather than asking you to trust this page.
solutions/ex06.md
# Solution to Exercise 6: a trace table for `/ops` (Part 7)
| Region of `app/ops/page.tsx` | Static shell or streamed-uncached? | Evidence |
|---|---|---|
| `<h1>Saathi Ops Console</h1>` | Static shell | No `await` above this line in the component tree |
| `getTodaysSummary()` → the deliveries/avg-time paragraph | Static shell | The function itself has no `await` at all — it completes during prerendering regardless of Suspense, per this part's README section 7 and Part 7's own section 2 |
| `<LiveDelayedOrders />` (1200ms simulated delay) | Streamed, uncached | Wrapped in its own `<Suspense>`; no `"use cache"` anywhere in `getDelayedOrders` |
| `<NearbyPartners />` (500ms simulated delay) | Streamed, uncached | Same pattern, different `<Suspense>` boundary, different delay |
Evidence for the two streamed rows, read directly from the build output on disk:
```text
$ python3 -c "print('ORD-4821' in open('harness/.next/server/app/ops.html').read())"
False
$ python3 -c "print('partners online' in open('harness/.next/server/app/ops.html').read())"
False
```
Neither the delayed-orders list nor the partner count is present in the prerendered shell — only the `<h1>`, the summary paragraph, and both Suspense fallback texts are. This is the same method Part 8's own `examples/04-rendering-trace.md` used for `/status`, applied here to a page built in a different part of this course, with its own independent evidence rather than reused numbers.
solutions/ex07.md
# Solution to Exercise 7: flip the gap yourself, on a different function
In a scratch copy of `app/ops/lib/delay.ts`, add `"use cache"` to `getNearbyPartnerCount`:
```ts
export async function getNearbyPartnerCount(city: string): Promise<number> {
"use cache";
await wait(500);
return nearbyPartnerCounts[city] ?? 0;
}
```
Real build, run against this course's harness:
```text
$ npm run build
...
├ ◐ /ops 15m 1y
├ ◐ /ops/orders
```
`/ops` stays `◐` overall — `LiveDelayedOrders`/`getDelayedOrders` is still uncached, so the route as a whole still has a genuinely streamed section. But the specific function you cached now bakes its result into the shell:
```text
$ python3 -c "print('partners online' in open('.next/server/app/ops.html').read())"
True
```
Two separate granularities, confirmed on two different pages now: this part's own section 5 showed `generateStaticParams` vs `"use cache"` as two different *decisions* on the same function (`lookupPnr`); this exercise shows a route's single `◐`/`○` symbol is a route-wide summary, while individual functions inside it can each be cached or not, independently of their siblings. Revert the change afterward — `getNearbyPartnerCount` stays uncached in this part's canonical harness state, because Part 7's whole point was watching it stream.
solutions/ex08.md
# Solution to Exercise 8 (stretch): auditing this part's `(varies)` claims
Reading back through Part 8's README with this question in mind:
**Would differ on a different machine/run — genuinely `(varies)`:**
- Every port number (`PORT` placeholders throughout)
- The `digest` hash quoted in Part 7 (carried into this part's cross-references) — it's a hash of the error, not a stable id
- Anything timing-related inherited from Part 7's examples (millisecond arrival times)
- The full `AppRoutes` list beyond this part's own two routes (Exercise 4) — it depends on whatever else has been built into the shared harness at the time you run it
- Build durations, if quoted (this part mostly avoided quoting them, on purpose)
**Would NOT differ — stable facts, safe to rely on:**
- Route table symbols (`○`, `◐`, `ƒ`) for a given, unchanged page — these are determined by the code, not the machine
- HTTP status codes (`200` for the unknown-PNR case, every time)
- Header **names** (`x-nextjs-cache`, `x-nextjs-postponed`, `x-nextjs-prerender`, `x-nextjs-stale-time`) — their presence/absence is deterministic for a given route's rendering mode, though the `stale-time` number itself comes from `cacheLife` and would change if that changed
- The literal deprecation text in `config-shared.d.ts` and `migrating-to-cache-components.md` — stable for this exact installed version, `16.4.6`, and worth re-checking (not re-trusting) against any other version
- Byte-presence checks (`"Karnataka" in ...html`) — either the string is there or it isn't, for a given build
The habit this exercise is actually training: before writing a number down as fact, ask "if I ran this again right now, on this machine, would I get the same thing?" If the answer is "probably, within noise," it's a real fact. If the answer is "only if nothing in the universe changed between runs," it's `(varies)`, and should be labeled that way rather than presented as a fixed property of Next.js.
experimental_ppr
Removed. Enable cacheComponents instead. Next.js 16 removes the experimental Partial Prerendering flag (experimental.ppr) and the experimental_ppr route segment config. Partial Prerendering is now part of Cache Components...
The `ppr` config field still exists in the installed package's own TypeScript types, but it is marked `@deprecated` in that very same file, with an explicit note that the real feature now ships through `cacheComponents` — the setting this course's harness has had turned on since Part 1. Every `◐` this course has produced since Part 1, section 6, **is** Partial Prerendering, with no separate flag ever needed. The installed package's own glossary confirms the concept hasn't gone away, only the opt-in mechanism has:
> "**Partial Prerendering (PPR)**: A rendering optimization that combines prerendering and dynamic rendering in a single route. The static shell is served immediately while dynamic content streams in when ready..."
**Don't trust this summary either, by the time you read it** — re-run the two `grep`/`sed` commands above against whatever version is actually installed. This course's own stated rule (`README.md`, "How this course is verified") is exactly for moments like this one: Next.js's rendering model has already gone through three generations (route-segment config → `experimental.ppr`/`dynamicIO` → default-on Cache Components) in recent major versions, so a claim about "the current PPR flag" ages faster than almost anything else in this course.
## Common mistakes
| Mistake | Why it is wrong | Fix |
|---|---|---|
| Reading `◐` as "this route is half-static, half-broken" | It's a deliberate, working combination of a prerendered shell and streamed sections — Part 7's entire mechanism | Read the route table alongside the actual page to see which sections are which, as section 3's trace does |
| Assuming `generateStaticParams` bakes in the data a Suspense-wrapped component fetches | Section 3 proves otherwise directly — the prerendered HTML for a listed param contained only the fallback text | Add `"use cache"` (Stage 3) to the data-fetching function if you also want the result baked in |
| Treating an unlisted-but-valid dynamic param as "the slow path" vs listed ones | Section 3's header comparison shows identical `x-nextjs-prerender`/`x-nextjs-postponed` values — both reuse the same App Shell mechanism | Don't special-case unlisted params in your own reasoning; `dynamicParams` (default `true`) is exactly what makes this uniform |
| Quoting "Partial Prerendering is experimental, behind `experimental.ppr`" | That flag is deprecated and removed in this installed version — confirmed directly in section 6 | Check `node_modules/next/dist/server/config-shared.d.ts` and the migration guide in the version you actually have installed |
| Expecting a `notFound()` thrown behind a streamed Suspense boundary to return a real `404` | The shell's `200` was already sent; Part 7 section 7 and this part's section 3 both reproduce the same `200` + `noindex` outcome | For a true request-time `404`, run the check before any Suspense boundary starts streaming (Stage 3/4's Proxy) |
## Quick recap
- Next.js decides static vs dynamic per **component**, not per route — the installed package's own rendering-philosophy guide states this directly, and this part's two pages prove it with real bytes.
- `○`/`◐`/`ƒ` are claims about *when* a route's HTML was produced, not quality grades — `◐` means "shell at build time, some sections streamed at request time," by design.
- `generateStaticParams` controls which URLs get a prerendered shell; `"use cache"` controls whether the data inside a Suspense boundary gets baked in too — they are two separate decisions, provable by flipping one without the other.
- `cookies()`, `headers()`, and `searchParams` force request-time work because the values genuinely don't exist until a request arrives; `params` behaves the same way unless `generateStaticParams` lists it.
- Partial Prerendering has no separate opt-in flag in this installed version — `experimental.ppr` is deprecated and folded into `cacheComponents`, confirmed directly from the package on disk, not assumed.
- Choose static for anything request-invariant, cached for shared-but-expensive data, streamed-uncached for cheap-or-must-be-fresh data behind a boundary, and fully dynamic only when a response genuinely can't start until something is checked first.
## Checklist
- [ ] I can state, in one sentence, why Next.js draws the static/dynamic line at the component level instead of the route level.
- [ ] I built a dynamic-segment page where a listed, prerendered param still streamed its real content fresh, and explained why using the actual prerendered HTML bytes.
- [ ] I built a page with `searchParams`, `cookies()`, and `headers()` each in their own Suspense-wrapped component, and proved each one varies per request.
- [ ] I confirmed, by reading the installed package's own files, that `experimental.ppr` is deprecated in this version and Partial Prerendering now lives inside `cacheComponents`.
- [ ] I flipped a route from `◐` to `○` by adding `"use cache"` to the one function responsible, and watched the real build output and HTML change.
- [ ] I can say which of the four rows in section 7's table a new page's data should land in, before writing any code for it.