@rangojs/router 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/types/browser/cookie-name.d.ts +6 -0
- package/dist/types/browser/history-state.d.ts +16 -0
- package/dist/types/cache/cache-key-utils.d.ts +17 -2
- package/dist/types/cache/cache-policy.d.ts +17 -0
- package/dist/types/cache/cache-scope.d.ts +98 -14
- package/dist/types/cache/cache-tag.d.ts +92 -7
- package/dist/types/cache/cf/cf-base64.d.ts +6 -0
- package/dist/types/cache/cf/cf-cache-constants.d.ts +11 -0
- package/dist/types/cache/cf/cf-cache-store.d.ts +185 -44
- package/dist/types/cache/cf/cf-cache-types.d.ts +31 -4
- package/dist/types/cache/cf/cf-shell-frame.d.ts +95 -0
- package/dist/types/cache/cf/cf-tag-marker-memo.d.ts +34 -0
- package/dist/types/cache/handle-snapshot.d.ts +4 -3
- package/dist/types/cache/index.d.ts +1 -0
- package/dist/types/cache/isolate-tag-memo.d.ts +149 -0
- package/dist/types/cache/shell-memo.d.ts +178 -0
- package/dist/types/cache/shell-snapshot.d.ts +110 -21
- package/dist/types/cache/tag-invalidation.d.ts +30 -3
- package/dist/types/cache/types.d.ts +207 -43
- package/dist/types/cache/vercel/vercel-cache-store.d.ts +111 -13
- package/dist/types/prerender/build-shell-capture.d.ts +11 -4
- package/dist/types/router/instrument.d.ts +8 -0
- package/dist/types/router/middleware-types.d.ts +6 -1
- package/dist/types/router/segment-resolution/loader-cache.d.ts +40 -11
- package/dist/types/router/segment-resolution/loader-snapshot.d.ts +21 -10
- package/dist/types/router/segment-resolution/mask-nested.d.ts +65 -24
- package/dist/types/rsc/full-payload.d.ts +14 -0
- package/dist/types/rsc/handler.d.ts +1 -1
- package/dist/types/rsc/shell-build-manifest.d.ts +8 -0
- package/dist/types/rsc/shell-capture-constants.d.ts +53 -6
- package/dist/types/rsc/shell-capture.d.ts +146 -15
- package/dist/types/rsc/shell-serve.d.ts +140 -17
- package/dist/types/rsc/types.d.ts +7 -0
- package/dist/types/server/context.d.ts +109 -15
- package/dist/types/server/cookie-store.d.ts +21 -0
- package/dist/types/server/request-context.d.ts +159 -33
- package/dist/types/ssr/index.d.ts +9 -0
- package/dist/types/ssr/ssr-root.d.ts +9 -8
- package/dist/types/testing/flight.entry.d.ts +7 -0
- package/dist/types/testing/run-loader.d.ts +18 -3
- package/dist/types/testing/serve-shell-request.d.ts +132 -0
- package/dist/types/testing/shell-status.d.ts +23 -10
- package/dist/types/types/handler-context.d.ts +14 -1
- package/dist/types/urls/pattern-types.d.ts +22 -18
- package/dist/types/vite/router-discovery.d.ts +29 -2
- package/dist/vite/index.js +46 -9
- package/package.json +1 -1
- package/skills/breadcrumbs/SKILL.md +17 -7
- package/skills/cache-guide/SKILL.md +123 -51
- package/skills/caching/SKILL.md +253 -23
- package/skills/catalog.json +1 -1
- package/skills/client-urls/SKILL.md +11 -6
- package/skills/cloudflare/SKILL.md +15 -0
- package/skills/comparison/references/framework-comparison.md +44 -32
- package/skills/defer-hydration/SKILL.md +50 -30
- package/skills/deployment-caching/SKILL.md +5 -2
- package/skills/document-cache/SKILL.md +8 -2
- package/skills/handler-use/SKILL.md +2 -0
- package/skills/hooks/handle-and-actions.md +3 -1
- package/skills/hooks/state.md +3 -1
- package/skills/loader/SKILL.md +161 -39
- package/skills/middleware/SKILL.md +16 -9
- package/skills/migrate-nextjs/SKILL.md +67 -36
- package/skills/migrate-react-router/SKILL.md +2 -1
- package/skills/migrate-react-router/component-migration.md +3 -1
- package/skills/migrate-react-router/data-and-actions.md +3 -1
- package/skills/migrate-react-router/route-mapping.md +7 -4
- package/skills/observability/SKILL.md +64 -0
- package/skills/parallel/SKILL.md +13 -8
- package/skills/ppr/SKILL.md +655 -363
- package/skills/prerender/SKILL.md +27 -14
- package/skills/rango/SKILL.md +52 -33
- package/skills/route/SKILL.md +12 -7
- package/skills/router-setup/SKILL.md +4 -2
- package/skills/scripts/SKILL.md +8 -1
- package/skills/server-actions/SKILL.md +11 -0
- package/skills/shell-manifest/SKILL.md +21 -12
- package/skills/testing/SKILL.md +25 -21
- package/skills/testing/cache-prerender.md +15 -14
- package/skills/testing/loader.md +18 -1
- package/skills/testing/serve-shell-request.md +188 -0
- package/skills/theme/SKILL.md +52 -4
- package/skills/typesafety/env-and-bindings.md +10 -2
- package/skills/use-cache/SKILL.md +39 -16
- package/skills/vercel/SKILL.md +14 -2
- package/skills/view-transitions/SKILL.md +1 -1
- package/src/browser/cookie-name.ts +23 -0
- package/src/browser/history-state.ts +23 -0
- package/src/browser/rsc-router.tsx +5 -0
- package/src/cache/cache-key-utils.ts +22 -2
- package/src/cache/cache-policy.ts +22 -0
- package/src/cache/cache-runtime.ts +34 -7
- package/src/cache/cache-scope.ts +345 -33
- package/src/cache/cache-tag.ts +375 -11
- package/src/cache/cf/cf-base64.ts +36 -4
- package/src/cache/cf/cf-cache-constants.ts +12 -0
- package/src/cache/cf/cf-cache-store.ts +990 -348
- package/src/cache/cf/cf-cache-types.ts +32 -4
- package/src/cache/cf/cf-shell-frame.ts +258 -0
- package/src/cache/cf/cf-tag-marker-memo.ts +143 -39
- package/src/cache/handle-snapshot.ts +4 -3
- package/src/cache/index.ts +2 -0
- package/src/cache/isolate-tag-memo.ts +308 -0
- package/src/cache/shell-memo.ts +341 -0
- package/src/cache/shell-snapshot.ts +217 -27
- package/src/cache/tag-invalidation.ts +104 -19
- package/src/cache/types.ts +211 -43
- package/src/cache/vercel/vercel-cache-store.ts +545 -61
- package/src/prerender/build-shell-capture.ts +65 -11
- package/src/route-definition/dsl-helpers.ts +4 -3
- package/src/router/handler-context.ts +38 -4
- package/src/router/instrument.ts +54 -2
- package/src/router/intercept-resolution.ts +19 -7
- package/src/router/loader-resolution.ts +63 -32
- package/src/router/match-api.ts +28 -9
- package/src/router/match-handlers.ts +5 -0
- package/src/router/match-middleware/cache-lookup.ts +17 -0
- package/src/router/match-middleware/cache-store.ts +31 -11
- package/src/router/middleware-types.ts +6 -1
- package/src/router/middleware.ts +23 -4
- package/src/router/prerender-match.ts +6 -0
- package/src/router/segment-resolution/fresh.ts +18 -9
- package/src/router/segment-resolution/helpers.ts +4 -2
- package/src/router/segment-resolution/loader-cache.ts +227 -56
- package/src/router/segment-resolution/loader-snapshot.ts +203 -51
- package/src/router/segment-resolution/mask-nested.ts +136 -42
- package/src/router/segment-resolution/revalidation.ts +27 -10
- package/src/rsc/full-payload.ts +25 -1
- package/src/rsc/handler.ts +14 -2
- package/src/rsc/progressive-enhancement.ts +3 -2
- package/src/rsc/response-cache-serve.ts +9 -6
- package/src/rsc/rsc-rendering.ts +601 -181
- package/src/rsc/shell-build-manifest.ts +27 -9
- package/src/rsc/shell-capture-constants.ts +60 -6
- package/src/rsc/shell-capture.ts +1001 -250
- package/src/rsc/shell-serve.ts +316 -34
- package/src/rsc/types.ts +7 -0
- package/src/server/context.ts +219 -28
- package/src/server/cookie-store.ts +87 -62
- package/src/server/request-context.ts +263 -38
- package/src/ssr/index.tsx +96 -37
- package/src/ssr/ssr-root.tsx +9 -8
- package/src/testing/flight.entry.ts +14 -0
- package/src/testing/run-loader.ts +63 -5
- package/src/testing/serve-shell-request.ts +378 -0
- package/src/testing/shell-status.ts +34 -12
- package/src/theme/ThemeProvider.tsx +7 -6
- package/src/types/handler-context.ts +14 -1
- package/src/urls/pattern-types.ts +22 -18
- package/src/vite/discovery/shell-prerender-phase.ts +9 -0
- package/src/vite/router-discovery.ts +14 -4
package/skills/ppr/SKILL.md
CHANGED
|
@@ -10,10 +10,9 @@ Caches the rendered HTML **shell** of a page route (React `prerender` prelude
|
|
|
10
10
|
bytes plus `postponed` state) and, on a later request, flushes those bytes after
|
|
11
11
|
route classification and the complete middleware chain, but before downstream
|
|
12
12
|
tail rendering. It then resumes React's HTML renderer for just the live holes.
|
|
13
|
-
The browser sees one ordinary streamed document; loaders
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
falls open to it.
|
|
13
|
+
The browser sees one ordinary streamed document; live loaders (no `ssr: false`)
|
|
14
|
+
stay fresh on every request. A normal render (no shell) is untouched, and every
|
|
15
|
+
request the shell cannot serve falls open to it.
|
|
17
16
|
|
|
18
17
|
Use it when a page has a stable layout that should reach the browser instantly
|
|
19
18
|
(the first byte comes from cache) while specific regions stay per-request:
|
|
@@ -24,8 +23,9 @@ doctrine").
|
|
|
24
23
|
Compare `/document-cache`, which freezes the WHOLE response including loader
|
|
25
24
|
output, and the `cache()` DSL (`/caching`), which caches Flight segments but
|
|
26
25
|
still renders HTML on every request. Shell caching is for pages that mix a
|
|
27
|
-
stable shell with live data: the shell is shared per host+URL
|
|
28
|
-
|
|
26
|
+
stable shell with live data: the shell is shared per host+URL (and per request
|
|
27
|
+
partition, when the route's `cache({ key })` or the store's `keyGenerator`
|
|
28
|
+
partitions its record), the holes are per request.
|
|
29
29
|
|
|
30
30
|
This is in-function PPR on every deployment. The worker/function serves the
|
|
31
31
|
prelude; it is not a CDN static file. See `/deployment-caching` before combining
|
|
@@ -36,9 +36,9 @@ PPR with HTTP shared-cache headers.
|
|
|
36
36
|
- You want the WHOLE response frozen, loader output included — see
|
|
37
37
|
`/document-cache`.
|
|
38
38
|
- You want build-time Flight segment payloads from `Static()`/`Prerender()` —
|
|
39
|
-
see `/prerender`. A `Prerender` page may also declare `ppr`; then the
|
|
40
|
-
|
|
41
|
-
live.
|
|
39
|
+
see `/prerender`. A `Prerender` page may also declare `ppr`; then the
|
|
40
|
+
build-time shell capture bakes the HTML shell while loaders without
|
|
41
|
+
`ssr: false` stay live.
|
|
42
42
|
- You want cached segments with live loaders but no cached HTML — that is the
|
|
43
43
|
`cache()` DSL: see `/caching`.
|
|
44
44
|
- You are unsure which cache layer you need — start at `/cache-guide`.
|
|
@@ -51,7 +51,7 @@ only prerequisite is an app-level `createRouter({ cache })` store that
|
|
|
51
51
|
implements the shell family (`getShell`/`putShell`): `MemorySegmentCacheStore`
|
|
52
52
|
(dev/tests), `CFCacheStore` (Cache API L1 + optional KV L2), or
|
|
53
53
|
`VercelCacheStore` (Vercel Runtime Cache). A ppr route on a store without the
|
|
54
|
-
family
|
|
54
|
+
family renders normally (no shell) with a once-per-key warning.
|
|
55
55
|
|
|
56
56
|
```typescript
|
|
57
57
|
import { createRouter, urls } from "@rangojs/router";
|
|
@@ -82,70 +82,144 @@ export const router = createRouter<AppBindings>({
|
|
|
82
82
|
});
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
The live price above is a hole because it is LOADER data read under a
|
|
86
|
+
boundary. Everything the handler layer produces is shell material, the way it
|
|
87
|
+
is under `cache()`:
|
|
87
88
|
|
|
88
|
-
###
|
|
89
|
+
### Handler output always bakes, promises included
|
|
89
90
|
|
|
90
|
-
A
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
boundary; the boundary postpones at capture and becomes the hole:
|
|
91
|
+
A promise a handler passes to a component under `<Suspense>` is NOT a hole. The
|
|
92
|
+
capture waits for it, bakes the settled value into the prelude, and serves that
|
|
93
|
+
value for the shell's lifetime:
|
|
94
94
|
|
|
95
95
|
```typescript
|
|
96
|
-
// Handler:
|
|
96
|
+
// Handler: the fetch is not awaited here, but the capture awaits it.
|
|
97
97
|
function ProductPage(ctx: HandlerContext) {
|
|
98
|
-
const reviews = fetchReviews(ctx.params.id); // Promise<Review[]>
|
|
98
|
+
const reviews = fetchReviews(ctx.params.id); // Promise<Review[]>
|
|
99
99
|
return (
|
|
100
100
|
<main>
|
|
101
|
-
<h1>Product {ctx.params.id}</h1> {/* shell
|
|
102
|
-
<ReviewsSection promise={reviews} /> {/*
|
|
101
|
+
<h1>Product {ctx.params.id}</h1> {/* shell */}
|
|
102
|
+
<ReviewsSection promise={reviews} /> {/* shell too: the capture waits for
|
|
103
|
+
`reviews`, and every HIT shows
|
|
104
|
+
the capture's reviews */}
|
|
103
105
|
</main>
|
|
104
106
|
);
|
|
105
107
|
}
|
|
106
108
|
```
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
The same holds for an async server component (with or without a `<Suspense>`
|
|
111
|
+
above it), a promise nested in a handle the handler pushes
|
|
112
|
+
(`ctx.use(Handle)({ x: promise })`), and a loader the handler awaits
|
|
113
|
+
(`await ctx.use(Loader)`). The capture waits for all of it, bounded by ONE
|
|
114
|
+
deadline, `ppr.captureTimeout` (15s by default); handler output that has not
|
|
115
|
+
settled by then stores no shell (the once-per-key warning names the cause: "did
|
|
116
|
+
not settle within ppr.captureTimeout"). A shell HIT never runs a handler: it
|
|
117
|
+
replays the handler layer the capture recorded.
|
|
118
|
+
|
|
119
|
+
To keep a region fresh per request, load it in a loader WITHOUT `ssr: false`
|
|
120
|
+
and read it with `useLoader` under `loading()` or an inline `<Suspense>` (a live
|
|
121
|
+
hole, see "The hole doctrine"); inside a `loader(Def, { ssr: false })`, return
|
|
122
|
+
the live part as a nested promise.
|
|
123
|
+
|
|
124
|
+
A route WITHOUT the `ppr` option renders normally (no shell): no store read, no
|
|
125
|
+
capture, no logs, zero cost. `ppr` is per page route — declaring it on a layout
|
|
126
|
+
is not supported (subtree inheritance is a possible follow-up).
|
|
127
|
+
|
|
128
|
+
### Migration from the old promise-hole model
|
|
129
|
+
|
|
130
|
+
Earlier versions treated a pending handler promise under `<Suspense>` as a hole
|
|
131
|
+
and re-ran handlers on some HITs. That is gone:
|
|
132
|
+
|
|
133
|
+
Everything a handler produces is shell material, as it is under `cache()`: a
|
|
134
|
+
promise it passes to a component under `<Suspense>`, an async server component,
|
|
135
|
+
a nested promise in a handle it pushes, and a loader it awaits are all awaited
|
|
136
|
+
at capture (bounded by `ppr.captureTimeout`) and served frozen for the shell's
|
|
137
|
+
lifetime. A HIT never runs a handler. To keep a value fresh per request, load
|
|
138
|
+
it in a loader without `ssr: false` and read it with `useLoader` under
|
|
139
|
+
`loading()` or an inline `<Suspense>`; inside an `ssr: false` loader, return
|
|
140
|
+
that part as a nested promise. Request-scoped reads the capture now waits for
|
|
141
|
+
refuse it: `cookies()`, `headers()`, a `{ cache: false }` variable, and
|
|
142
|
+
`ctx.dynamic()` inside a handler promise, an async component, a handle push, or
|
|
143
|
+
a loader a handler awaits. A normal `ctx.get()` value is not guarded: shell
|
|
144
|
+
material is shared per host+URL and request partition. `cache(false)`, or a
|
|
145
|
+
`condition()` that returns false, on a ppr route now renders the request like a
|
|
146
|
+
cache miss (no shell).
|
|
147
|
+
|
|
148
|
+
### Request-partitioned shells
|
|
149
|
+
|
|
150
|
+
A route whose `cache()` record is partitioned by the request partitions its
|
|
151
|
+
shell the same way: the route's `cache({ key })`, or the store's
|
|
152
|
+
`keyGenerator`, decides which shell a request reads, captures and replays.
|
|
153
|
+
Each partition captures its own on its first request and never serves
|
|
154
|
+
another's:
|
|
113
155
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<Inner promise={promise} />
|
|
121
|
-
</Suspense>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
156
|
+
```tsx
|
|
157
|
+
cache(
|
|
158
|
+
{ ttl: 300, key: (ctx) => `tier:${ctx.request.headers.get("x-tier")}` },
|
|
159
|
+
() => [path("/pricing", PricingPage, { ppr: true })],
|
|
160
|
+
);
|
|
161
|
+
// gold and silver visitors each get their own /pricing shell.
|
|
124
162
|
```
|
|
125
163
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
164
|
+
The partition follows nested scopes (issue #970): a `ppr` route under a
|
|
165
|
+
`cache()` nested in a keyed one is partitioned by the outer `key()` when the
|
|
166
|
+
inner boundary has none, and by both composed (outermost first, each
|
|
167
|
+
URI-encoded, joined by `|`) when it has its own. The route's record adds the
|
|
168
|
+
inner boundary's own default key when it has no `key`; the shell partition
|
|
169
|
+
does not, since the shell key already carries the URL (a store
|
|
170
|
+
`keyGenerator`'s result is kept when it adds anything). See `/caching`,
|
|
171
|
+
"Keys nest".
|
|
130
172
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
173
|
+
```tsx
|
|
174
|
+
cache({ ttl: 300, key: (ctx) => `tier:${tierOf(ctx)}` }, () => [
|
|
175
|
+
layout(TierLayout, () => [
|
|
176
|
+
cache({ ttl: 60 }, () => [path("/pricing", PricingPage, { ppr: true })]),
|
|
177
|
+
]),
|
|
178
|
+
]);
|
|
179
|
+
// gold and silver still get their own /pricing shell and record.
|
|
180
|
+
```
|
|
137
181
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
182
|
+
This is the sanctioned way to vary shell material by request: the capture
|
|
183
|
+
guards still refuse `cookies()`/`headers()` in handler work, while the key
|
|
184
|
+
function reads what it needs (`cookies()` included). A `key()` runs once per
|
|
185
|
+
request: the shell read, the record lookup and the capture share its result
|
|
186
|
+
(each `key()` of a nested chain once).
|
|
187
|
+
One that throws serves no shell (like the record path renders uncached); a
|
|
188
|
+
store `keyGenerator` that returns the default key unchanged partitions
|
|
189
|
+
nothing. A partitioned route never serves a build-time shell (the build
|
|
190
|
+
captured one partition): each partition captures at runtime, and when the
|
|
191
|
+
route has a build shell a once-per-route warning says so. A `keyGenerator`
|
|
192
|
+
that returns the default key unchanged keeps the build shell.
|
|
193
|
+
|
|
194
|
+
Keep partition values to a small, known set: normalize what the key reads
|
|
195
|
+
(a tier, a locale) to the values you serve before returning it. Every
|
|
196
|
+
distinct value is a full capture and a stored shell, so a key that returns
|
|
197
|
+
raw header or cookie text lets any client mint new shells.
|
|
198
|
+
|
|
199
|
+
Query strings multiply shells the same way: the shell key includes the sorted
|
|
200
|
+
search, so a PDP reached as `/products/1?color=red&size=m` and
|
|
201
|
+
`?color=blue&size=m` has one shell per distinct query, and every appended
|
|
202
|
+
tracking param (`utm_*`, a click id) mints another. The router's
|
|
203
|
+
`cache.searchParams` option (`createRouter({ cache: { store, searchParams } })`)
|
|
204
|
+
drops params from the key, shell included
|
|
205
|
+
(`{ exclude: TRACKING_SEARCH_PARAMS }`, or an `{ include: [...] }` allowlist;
|
|
206
|
+
see `/caching`, "Search param key filtering"). Exclude only a param the shell
|
|
207
|
+
does not render from: otherwise the first variant captured is served for every
|
|
208
|
+
value of it.
|
|
209
|
+
|
|
210
|
+
In tests, `serveShellRequest` reports the key the serve path resolved
|
|
211
|
+
(`result.key`, partition included); `shellCacheKey(url, searchParams,
|
|
212
|
+
partition)` builds the same key from the partition. Under nested keyed
|
|
213
|
+
scopes, pass the `key()` results as an array, outermost first
|
|
214
|
+
(`shellCacheKey(url, undefined, ["tier:gold", "v:a"])`).
|
|
141
215
|
|
|
142
216
|
## Where PPR sits: the cache onion
|
|
143
217
|
|
|
144
|
-
Rango's caches layer like an onion — each
|
|
218
|
+
Rango's caches layer like an onion — each layer stores a progressively more
|
|
145
219
|
"cooked" representation of the same page. From innermost (raw values) to
|
|
146
220
|
outermost (final bytes):
|
|
147
221
|
|
|
148
|
-
|
|
|
222
|
+
| Layer | Primitive | What is stored | What stays live on a hit |
|
|
149
223
|
| ----------------------- | ---------------------------------------- | -------------------------------------------------- | -------------------------------------- |
|
|
150
224
|
| 1. Function values | `"use cache"` | a function's return value | everything around the call |
|
|
151
225
|
| 2. Loader values | `loader(Fn, () => [cache({...})])` | one loader's result (opt-in; loaders default live) | all other loaders, handlers, rendering |
|
|
@@ -153,13 +227,15 @@ outermost (final bytes):
|
|
|
153
227
|
| 4. **HTML shell (PPR)** | `ppr` path option | rendered prelude bytes + React postponed state | the holes, hydration payload |
|
|
154
228
|
| 5. Whole response | `/document-cache` | final response bytes, headers included | nothing — all-or-nothing |
|
|
155
229
|
|
|
156
|
-
PPR is ORTHOGONAL to `cache()` (
|
|
157
|
-
handlers run
|
|
158
|
-
segments
|
|
159
|
-
|
|
160
|
-
|
|
230
|
+
PPR is ORTHOGONAL to `cache()` (the segments layer): a ppr route may be
|
|
231
|
+
uncached (its handlers run on a MISS and during capture), fully `cache()`d
|
|
232
|
+
(the capture replays its segments), or mixed. Either way a HIT runs no
|
|
233
|
+
handler: the shell entry is itself a `cache()` of the handler layer, recorded
|
|
234
|
+
by the capture and replayed on every HIT. That is why handler promises cannot stay live under ppr:
|
|
235
|
+
the segment codec **deep-settles promises** when it writes a segment record,
|
|
236
|
+
under `cache()` and under the shell alike.
|
|
161
237
|
|
|
162
|
-
Invalidation crosses
|
|
238
|
+
Invalidation crosses layers: `updateTag()`/`revalidateTag()` reach segment,
|
|
163
239
|
shell, loader, and item entries in the same store, and shell entries
|
|
164
240
|
additionally self-invalidate on `React.version` change.
|
|
165
241
|
|
|
@@ -173,54 +249,99 @@ On a document GET to a ppr route the router runs:
|
|
|
173
249
|
them: any rejection/redirect/401 wins before a single shell byte, on MISS
|
|
174
250
|
and on a warmed HIT alike;
|
|
175
251
|
3. **shell lookup** — `getShell(key)` on the app store (key =
|
|
176
|
-
host+pathname+sorted search)
|
|
252
|
+
host+pathname+sorted search). `CFCacheStore` stores the entry prelude-first
|
|
253
|
+
and the serve path reads only its head and prelude here, with the tag-marker
|
|
254
|
+
read running alongside; the capture snapshot is read off the commit path.
|
|
255
|
+
`CFCacheStore` and `VercelCacheStore` keep the last fresh read of each shell
|
|
256
|
+
in a memo for `memo.shellMs` (default 2 s): a warm isolate's next HITs skip
|
|
257
|
+
the store read, but never the tag-marker check, which reads its markers
|
|
258
|
+
through a per-isolate stale-while-revalidate memo (`memo.markerFreshMs`,
|
|
259
|
+
`memo.markerMaxStaleMs`). The user whose request ran `updateTag()` /
|
|
260
|
+
`revalidateTag()` gets a fresh-reads cookie that skips both memos; past
|
|
261
|
+
them each store's own consistency applies (`VercelCacheStore`: fresh in
|
|
262
|
+
any region, `expireTag` is global; `CFCacheStore` with KV: fresh in the
|
|
263
|
+
colo that ran it, other colos once KV propagates the marker and
|
|
264
|
+
`tagCacheTtl` expires; KV-less purge mode: once the purge reaches the colo).
|
|
265
|
+
Other users see the invalidation once the marker memo refreshes (KV-less
|
|
266
|
+
purge mode and another Vercel region: once the shell window passes; see the
|
|
267
|
+
caching skill);
|
|
177
268
|
4. **HIT** — the composed response is committed immediately: the stored prelude
|
|
178
|
-
bytes flush first, while segment resolution, the
|
|
179
|
-
full hydration payload — there is no Flight-side resume), and
|
|
180
|
-
`resume` of just the holes run BEHIND them inside the response
|
|
181
|
-
|
|
269
|
+
bytes flush first (in 32 KB chunks), while segment resolution, the Flight
|
|
270
|
+
render (the full hydration payload — there is no Flight-side resume), and
|
|
271
|
+
the fizz `resume` of just the holes run BEHIND them inside the response
|
|
272
|
+
stream, starting a macrotask after the commit so they cannot delay the
|
|
273
|
+
prelude's write. Segment resolution replays the handler layer from the
|
|
274
|
+
shell's own recorded segments — NO handler runs on a HIT — and runs the
|
|
275
|
+
live loaders fresh (a promise-free bake-lane loader is served from the
|
|
276
|
+
shell, see "On a shell HIT");
|
|
277
|
+
5. **MISS** — a normal render (no shell), tagged `x-rango-shell: MISS`, plus a
|
|
182
278
|
background capture (stampede-guarded, retry-in-place, exponential backoff).
|
|
183
279
|
|
|
184
280
|
`x-rango-shell: HIT | MISS` is the observability header. Because the commit
|
|
185
281
|
point is after the chain, an unauthorized request NEVER sees shell bytes — put
|
|
186
282
|
auth middleware anywhere (global or route DSL) and it guards PPR for free.
|
|
187
283
|
|
|
284
|
+
A route whose own `cache()` scope refuses THIS request — `cache(false)`, or a
|
|
285
|
+
`condition()` that returns false — skips steps 3-5: the document renders like a
|
|
286
|
+
cache miss (a normal render, no shell), with no `x-rango-shell` header and no
|
|
287
|
+
capture scheduled.
|
|
288
|
+
|
|
289
|
+
If a HIT cannot read the shell's recorded segments, it never falls back to
|
|
290
|
+
running handlers behind the committed prelude: it ends the response with a
|
|
291
|
+
small script that reloads the page once with a `_rsc_shell=miss` query marker,
|
|
292
|
+
and a request carrying the marker renders like a cache miss (no shell, no
|
|
293
|
+
capture), so the reload cannot repeat. The router drops the marker from the
|
|
294
|
+
request before anything reads it (middleware, handlers, loaders, cache keys
|
|
295
|
+
and `useSearchParams` see the clean URL), and the browser drops it from the
|
|
296
|
+
address bar before the page hydrates. When the stored value is corrupt it
|
|
297
|
+
also replaces the entry with a placeholder the next request treats as a MISS
|
|
298
|
+
and schedules a recapture that heals the key; a snapshot read that was only
|
|
299
|
+
slow leaves the entry alone.
|
|
300
|
+
|
|
188
301
|
### Soft navigation caches and reuses the handler layer
|
|
189
302
|
|
|
190
303
|
In short: client-side (soft) navigations to a `ppr` route reuse the handler
|
|
191
|
-
segments captured with the shell, while loaders stay live.
|
|
192
|
-
configuring; the rest of this section explains the
|
|
193
|
-
for when you are debugging replay behavior.
|
|
304
|
+
segments captured with the shell, while loaders without `ssr: false` stay live.
|
|
305
|
+
Nothing needs configuring; the rest of this section explains the
|
|
306
|
+
`x-rango-ppr-replay` header for when you are debugging replay behavior.
|
|
194
307
|
|
|
195
308
|
Ordinary partial RSC navigations to a `ppr` URL use the same handler-layer cache
|
|
196
309
|
contract even when no document request has captured an HTML shell yet. When a
|
|
197
|
-
shell snapshot exists, the server replays
|
|
310
|
+
shell snapshot exists, the server replays the page's recorded segments from it.
|
|
198
311
|
On a cold partial request, normal matching renders the response and schedules a
|
|
199
312
|
background navigation-only shell capture; later navigations and prefetches
|
|
200
313
|
replay its eligible snapshot. In both cases `matchPartial()`:
|
|
201
314
|
|
|
202
315
|
- preserves client-owned shared layouts by segment id;
|
|
203
316
|
- returns only new or revalidating destination segments;
|
|
204
|
-
- runs DSL loaders fresh with their normal `loading()` streaming
|
|
317
|
+
- runs live DSL loaders fresh with their normal `loading()` streaming
|
|
318
|
+
behavior, and serves bake-lane loaders from the pins of a shell captured by a
|
|
319
|
+
document request; a snapshot captured by a navigation alone carries no pins,
|
|
320
|
+
and its replay runs them fresh (see below);
|
|
205
321
|
- keeps the existing prefetch key, source scope, and in-flight lock unchanged.
|
|
206
322
|
|
|
207
323
|
This is deliberately invisible to the browser: the response is the same
|
|
208
324
|
`RscPayload` shape as any other partial navigation. Captured item/response values
|
|
209
|
-
|
|
210
|
-
|
|
325
|
+
are NOT replayed on this path. Bake-lane loader pins are, when the replayed
|
|
326
|
+
snapshot is a shell a document request captured, as on a document HIT: a
|
|
327
|
+
promise-free `ssr: false` loader is served from its pin without running
|
|
328
|
+
(unless the capture marked it to run: see "On a shell HIT"), and one whose
|
|
329
|
+
return holds promises runs with its baked parts overlaid. A snapshot captured
|
|
330
|
+
by a navigation alone carries no pins, and its replay runs them fresh. Loaders
|
|
331
|
+
without `ssr: false` stay live.
|
|
211
332
|
|
|
212
333
|
A route's own `cache()` scope — including one inherited from an ancestor, the
|
|
213
334
|
common app-wide storefront shape — COMPOSES with replay instead of disabling
|
|
214
335
|
it. The explicit tier stays authoritative: its lookup runs first with its
|
|
215
336
|
normal store, key, TTL, SWR, tags, and condition, and when it supplies the
|
|
216
337
|
match the response reports `BYPASS; reason=explicit-cache-hit` (never a false
|
|
217
|
-
replay `HIT`). Only when the explicit tier misses
|
|
218
|
-
|
|
219
|
-
possible, a capture of such a route records the
|
|
220
|
-
shell snapshot IN ADDITION to the scope's normal store write;
|
|
338
|
+
replay `HIT`). Only when the explicit tier misses do the page's recorded
|
|
339
|
+
segments in the shell snapshot supply the match and report `HIT`. To make that
|
|
340
|
+
possible, a capture of such a route records the page's segments into the
|
|
341
|
+
shell snapshot IN ADDITION to the scope's normal store write; that record rides
|
|
221
342
|
only inside the shell entry, never the real store. Two opt-outs stay absolute:
|
|
222
343
|
`cache(false)` and a `condition()` returning false mean "do not serve this
|
|
223
|
-
request's segments from any cache" — no
|
|
344
|
+
request's segments from any cache" — no segments are recorded for them and
|
|
224
345
|
the seeded fallback never rescues a refused read. `cache(false)` is static, so
|
|
225
346
|
replay reports `BYPASS; reason=cache-disabled` before performing a single
|
|
226
347
|
shell read; a `condition()` refusal is request-time state, decided at the
|
|
@@ -228,15 +349,16 @@ lookup itself and reported as the same `cache-disabled` post-match (the gate
|
|
|
228
349
|
must not pre-decide a predicate that could flap between the two evaluations).
|
|
229
350
|
An errored explicit read — a throwing `key()`, or a built-in store's swallowed
|
|
230
351
|
backend failure (`CACHE_READ_ERROR`) — also never falls back: it renders
|
|
231
|
-
uncached, exactly as without ppr.
|
|
352
|
+
uncached, exactly as without ppr. (Document requests treat the same two
|
|
353
|
+
opt-outs as a cache miss before any shell read: see the serve pipeline above.)
|
|
232
354
|
|
|
233
355
|
`transition({ when })` is evaluated from the
|
|
234
356
|
matched manifest before route handlers on every PPR match, so it can vary by
|
|
235
357
|
URL/params/action or middleware context without disabling replay; handler-set
|
|
236
|
-
context is unavailable by design. Intercepts,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
358
|
+
context is unavailable by design. Intercepts, an active nonce, and an
|
|
359
|
+
absent/corrupt segment snapshot fall open to the ordinary partial path when
|
|
360
|
+
encountered by the shell capture. A transition already replayed from an
|
|
361
|
+
explicit cache tier remains frozen by that tier's normal semantics.
|
|
240
362
|
|
|
241
363
|
Two more decisions are made before any shell-store read, so probes and
|
|
242
364
|
prerendered routes never spend passive `getShell` I/O:
|
|
@@ -247,8 +369,8 @@ prerendered routes never spend passive `getShell` I/O:
|
|
|
247
369
|
with this in mind — such probes are not cache misses.
|
|
248
370
|
- A `Prerender()` route's partial is served from the build-time prerender
|
|
249
371
|
store inside matching (a better-than-HIT outcome); it reports
|
|
250
|
-
`BYPASS; reason=prerender-store`. Its captures never record
|
|
251
|
-
|
|
372
|
+
`BYPASS; reason=prerender-store`. Its captures never record the page's
|
|
373
|
+
segments (the prerender store short-circuits the cache write), so replay
|
|
252
374
|
seeding would be impossible anyway.
|
|
253
375
|
|
|
254
376
|
Fresh and stale-within-SWR runtime shells replay. The stale read is passive: it
|
|
@@ -291,17 +413,17 @@ consumer-invisible.
|
|
|
291
413
|
|
|
292
414
|
The bounded bypass tokens, grouped by when they are decided:
|
|
293
415
|
|
|
294
|
-
| Token | Decided | Meaning
|
|
295
|
-
| --------------------------------------------------------------------------------- | ----------------- |
|
|
296
|
-
| `method`, `dynamic`, `nonce`, `store-unavailable`, `passive-read-unsupported` | pre-read | request/route/store ineligible for replay
|
|
297
|
-
| `no-navigation-context` | pre-read | no `X-RSC-Router-Client-Path`/`Referer`; a partial match is impossible
|
|
298
|
-
| `prerender-store` | pre-read or match | `Prerender()` route served by its baked artifact (pre-read probe of the normal variant; reclassified post-match when the store actually served, either variant)
|
|
299
|
-
| `intercept` | match | the navigation resolved to an intercept — replay is never armed for intercepts (they keep their normal cache path); no heal capture
|
|
300
|
-
| `cache-disabled` | pre-read or match | `cache(false)` (pre-read, static) or `condition()` false (decided at the lookup); consumer opt-out is absolute
|
|
301
|
-
| `read-error`, `no-entry`, `invalid-version`, `corrupt-entry`, `stale-build-entry` | shell read | no usable shell entry (`no-entry`/`invalid-version`/`corrupt-entry`/`stale-build-entry` schedule the navigation-only heal capture)
|
|
302
|
-
| `
|
|
303
|
-
| `explicit-cache-hit` | match | the route's own `cache()` tier supplied the match
|
|
304
|
-
| `snapshot-miss` | match | an eligible snapshot was seeded but matching did not consume it
|
|
416
|
+
| Token | Decided | Meaning |
|
|
417
|
+
| --------------------------------------------------------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
418
|
+
| `method`, `dynamic`, `nonce`, `store-unavailable`, `passive-read-unsupported` | pre-read | request/route/store ineligible for replay |
|
|
419
|
+
| `no-navigation-context` | pre-read | no `X-RSC-Router-Client-Path`/`Referer`; a partial match is impossible |
|
|
420
|
+
| `prerender-store` | pre-read or match | `Prerender()` route served by its baked artifact (pre-read probe of the normal variant; reclassified post-match when the store actually served, either variant) |
|
|
421
|
+
| `intercept` | match | the navigation resolved to an intercept — replay is never armed for intercepts (they keep their normal cache path); no heal capture |
|
|
422
|
+
| `cache-disabled` | pre-read or match | `cache(false)` (pre-read, static) or `condition()` false (decided at the lookup); consumer opt-out is absolute |
|
|
423
|
+
| `read-error`, `no-entry`, `invalid-version`, `corrupt-entry`, `stale-build-entry` | shell read | no usable shell entry (`no-entry`/`invalid-version`/`corrupt-entry`/`stale-build-entry` schedule the navigation-only heal capture) |
|
|
424
|
+
| `no-segment-snapshot` | eligibility | entry exists but its snapshot has no recorded segments for the page; on a route with an enabled `cache()` scope, it heals when the lookup did not refuse (a `condition()` false-at-capture entry becomes replayable) |
|
|
425
|
+
| `explicit-cache-hit` | match | the route's own `cache()` tier supplied the match |
|
|
426
|
+
| `snapshot-miss` | match | an eligible snapshot was seeded but matching did not consume it |
|
|
305
427
|
|
|
306
428
|
### Capture-generation invalidation
|
|
307
429
|
|
|
@@ -313,11 +435,14 @@ out of render code if you want the shell to persist.
|
|
|
313
435
|
|
|
314
436
|
### Opting out per request with `ctx.dynamic()`
|
|
315
437
|
|
|
316
|
-
Middleware and handlers can call `ctx.dynamic()` to force this request
|
|
317
|
-
|
|
318
|
-
shell lookup, HIT serving, and MISS capture for that request.
|
|
438
|
+
Middleware and handlers can call `ctx.dynamic()` to force this request onto a
|
|
439
|
+
normal render (no shell). In middleware it runs before the PPR commit point, so
|
|
440
|
+
the router skips shell lookup, HIT serving, and MISS capture for that request.
|
|
441
|
+
In handlers it is
|
|
319
442
|
too late to prevent a MISS render from already happening, but it still prevents
|
|
320
|
-
the follow-up shell capture.
|
|
443
|
+
the follow-up shell capture. A `ctx.dynamic()` call that only happens during the
|
|
444
|
+
capture itself (for example inside a handler promise, after an await) refuses
|
|
445
|
+
that capture: a dynamic render has no shell.
|
|
321
446
|
|
|
322
447
|
During `Prerender` + `ppr` build-shell capture, middleware is replayed with
|
|
323
448
|
`ctx.build === true`, `ctx.waitUntil()` inert, and the same `ctx.dynamic()`
|
|
@@ -354,9 +479,10 @@ curl -s -D - -o /dev/null https://app.example.com/products/1 | grep -i x-rango-s
|
|
|
354
479
|
- Runtime-captured route: first document GET is `MISS`, plus a background
|
|
355
480
|
capture; a later request becomes a `HIT`.
|
|
356
481
|
- `Prerender + ppr` route: the shell is produced during `vite build`, so the
|
|
357
|
-
first production document request can already be a `HIT`. In dev,
|
|
358
|
-
runs on demand and can return a `HIT`; if capture
|
|
359
|
-
foreground wait, the request falls open to `MISS` and
|
|
482
|
+
first production document request can already be a `HIT`. In dev, the
|
|
483
|
+
build-time shell capture runs on demand and can return a `HIT`; if capture
|
|
484
|
+
outlasts the bounded foreground wait, the request falls open to `MISS` and
|
|
485
|
+
runtime capture.
|
|
360
486
|
- Production (workerd/node): the SECOND request is a `HIT`.
|
|
361
487
|
- Dev: expect a few extra MISSes — cold module transforms abort the capture
|
|
362
488
|
window (per-attempt breadcrumbs: start the server with
|
|
@@ -367,8 +493,9 @@ curl -s -D - -o /dev/null https://app.example.com/products/1 | grep -i x-rango-s
|
|
|
367
493
|
your baked shell, with hole fallbacks in place), then
|
|
368
494
|
`<div hidden id="S:0">…` segments as the holes resume, per request.
|
|
369
495
|
- A ppr-declared route that CANNOT be honored (missing shell store family,
|
|
370
|
-
per-request nonce) serves
|
|
371
|
-
key — no header + a declared `ppr` means look for that
|
|
496
|
+
per-request nonce) serves a normal render (no shell) with NO header and
|
|
497
|
+
warns once per key — no header + a declared `ppr` means look for that
|
|
498
|
+
warning.
|
|
372
499
|
- On Cloudflare, `CFCacheStore` reads PPR shells from the per-colo Cache API,
|
|
373
500
|
falls through to KV on a miss, and promotes the KV hit back into that colo.
|
|
374
501
|
WITHOUT a KV namespace the family runs L1-only (edge-only ppr): every colo
|
|
@@ -392,23 +519,28 @@ curl -s -D - -o /dev/null https://app.example.com/products/1 | grep -i x-rango-s
|
|
|
392
519
|
captures outrank queued navigation-only snapshots, but never interrupt the
|
|
393
520
|
active capture — the skip event and the `rango.background` span carry
|
|
394
521
|
`queuePriority`/`queueAhead` (class and backlog at enqueue) so a parked
|
|
395
|
-
capture diagnoses itself. A stored attempt reports `
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
522
|
+
capture diagnoses itself. A stored attempt reports `recordSettleMs`
|
|
523
|
+
(`record=` in the log line): how long the capture waited for the handler
|
|
524
|
+
layer to settle (promises it passes or pushes, async server components,
|
|
525
|
+
loaders it awaits) and its segment record to encode; `bakeWaitMs` (`bake=`):
|
|
526
|
+
how long the slowest remaining bake source (a top-level pushed handle promise
|
|
527
|
+
or a bake-lane loader container) held the capture gate; and `entryBytes`
|
|
528
|
+
(`entry=`): the stored entry's size. In dev, past 2s, the slow source is also
|
|
529
|
+
named once per key in a console warning with the remedies (`cache()` the
|
|
530
|
+
work / move it into a live loader / return it as a nested promise or drop
|
|
531
|
+
`ssr: false` in a bake-lane loader). In dev, with
|
|
400
532
|
`debugPerformance` on, the last capture outcome for a key also rides the
|
|
401
533
|
next document GET's `Server-Timing` as `ppr-capture;desc="…"`.
|
|
402
534
|
- For deployed Cloudflare tier diagnostics, build with
|
|
403
535
|
`INTERNAL_RANGO_DEBUG=1` and run `wrangler tail`. `[CFCacheStore][shell]`
|
|
404
|
-
JSON events distinguish L1 hit/miss, KV fallback/promotion, tier
|
|
405
|
-
marker rejection, with `cf-ray`/colo and read timings. The flag is baked at
|
|
536
|
+
JSON events distinguish memo hits, L1 hit/miss, KV fallback/promotion, tier
|
|
537
|
+
writes, and marker rejection, with `cf-ray`/colo and read timings. The flag is baked at
|
|
406
538
|
build time; setting only a Worker runtime variable is too late.
|
|
407
539
|
|
|
408
540
|
### Unit / integration testing (public primitives)
|
|
409
541
|
|
|
410
542
|
Import from `@rangojs/router/testing` (Vitest) or `@rangojs/router/testing/e2e`
|
|
411
|
-
(Playwright)
|
|
543
|
+
(Playwright); `serveShellRequest` from `@rangojs/router/testing/flight`:
|
|
412
544
|
|
|
413
545
|
| Helper | Use for |
|
|
414
546
|
| ------------------------------------------------- | ------------------------------------------------------------ |
|
|
@@ -417,6 +549,7 @@ Import from `@rangojs/router/testing` (Vitest) or `@rangojs/router/testing/e2e`
|
|
|
417
549
|
| `parsePprReplayStatus(res)` | Read structured replay/bypass status or null |
|
|
418
550
|
| `shellCacheKey(url)` | Production store key for `store.getShell` / custom stores |
|
|
419
551
|
| `MemorySegmentCacheStore` + `getShell`/`putShell` | Custom store contract / tag eviction (no faked HIT) |
|
|
552
|
+
| `serveShellRequest(router, url, opts)` | A real MISS → capture → HIT (react-server Vitest) |
|
|
420
553
|
|
|
421
554
|
```ts
|
|
422
555
|
import { MemorySegmentCacheStore } from "@rangojs/router/cache";
|
|
@@ -432,27 +565,49 @@ expect(await store.getShell(key)).not.toBeNull();
|
|
|
432
565
|
assertShellStatus({ headers: new Headers(res.headers()) }, "HIT");
|
|
433
566
|
```
|
|
434
567
|
|
|
435
|
-
**Out of unit scope** (stay e2e):
|
|
436
|
-
browser resume of holes, build-time
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
`
|
|
568
|
+
**Out of unit scope** (stay e2e): real HTML (the prelude bytes and the fizz
|
|
569
|
+
resume), browser resume of holes, the build-time shell capture. A MISS →
|
|
570
|
+
capture → HIT runs in a unit test through `serveShellRequest` from
|
|
571
|
+
`@rangojs/router/testing/flight`: the shell as captured is `result.prelude`,
|
|
572
|
+
the live tail is `result.flight`. "A HIT runs no handler and shows the
|
|
573
|
+
capture's handler output" is assertable there: count handler runs or render a
|
|
574
|
+
per-run stamp, then compare the MISS and a later HIT. `dispatch` never runs
|
|
575
|
+
PPR. `renderHandler` only exposes `ctx.dynamic()` / `build` for the opt-out
|
|
576
|
+
path. Do not invent a HIT Response in unit tests. Full recipe: `/testing`
|
|
577
|
+
skill → `serve-shell-request.md` and `cache-prerender.md` (PPR shell section).
|
|
440
578
|
|
|
441
579
|
## The hole doctrine (encode this in your head)
|
|
442
580
|
|
|
443
|
-
Holes are **render-defined**, decided by the shape of the tree
|
|
581
|
+
Holes are **render-defined**, decided by the shape of the tree. There are two
|
|
582
|
+
classes, and the handler layer is always on the SHELL side:
|
|
583
|
+
|
|
584
|
+
| Class | What decides it | At capture | At serve (HIT) |
|
|
585
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
586
|
+
| **STRUCTURAL** | a LIVE-lane loader (no `ssr: false`) read under a boundary: `loading()` (the whole segment subtree under it) or an inline `<Suspense>` above the reader | live loaders masked; the boundary postpones; its fallback bakes in as route structure | loaders run fresh; resume fills the hole |
|
|
587
|
+
| **SHELL** | everything the handler layer produces — awaited data, a promise it passes as a prop (even under the consumer's `<Suspense>`), an async server component, handle pushes at any depth, a loader it awaits (`await ctx.use(Loader)`) — plus replayed `cache()` segments and the settled non-promise data of BAKE-lane (`ssr: false`) loaders | awaited (one deadline, `ppr.captureTimeout`) and baked into the prelude and the shell's recorded segments | served from the frozen prelude; no handler runs |
|
|
444
588
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
589
|
+
One hole lives INSIDE loader data, decided by shape: a promise nested in a
|
|
590
|
+
bake-lane loader's return value, or in a handle container a loader pushes, is
|
|
591
|
+
masked at capture however fast it settles, and postpones at the consumer's own
|
|
592
|
+
`<Suspense>`. Such a loader still runs on every HIT, so that promise streams in
|
|
593
|
+
fresh (a promise-free bake-lane loader does not run on a HIT; see "On a shell
|
|
594
|
+
HIT").
|
|
450
595
|
|
|
451
|
-
|
|
452
|
-
|
|
596
|
+
The promise rule, by producer: **a promise a handler produces bakes, at any
|
|
597
|
+
depth; a promise nested in loader data stays live.** A
|
|
453
598
|
`loader(Def, { ssr: false })` is the BAKE lane (see the lane rule below): its
|
|
454
|
-
settled non-promise data is shell material, exactly like
|
|
455
|
-
|
|
599
|
+
settled non-promise data is shell material, exactly like handler output, while
|
|
600
|
+
its nested promises are holes. A live-lane loader is a hole as a whole.
|
|
601
|
+
`ssr: false` on a loader is the same knob as `loading(fallback, { ssr: false })`:
|
|
602
|
+
the document does not stream a fallback for it but resolves the loader before
|
|
603
|
+
the first flush, so under `ppr` its value lands in the prelude and bakes into
|
|
604
|
+
the shell. Delivery details: `/loader` → "`ssr: false` — Guarantee a Loader in
|
|
605
|
+
the Document".
|
|
606
|
+
|
|
607
|
+
An async server component that never settles inside `ppr.captureTimeout`
|
|
608
|
+
(with or without `<Suspense>` above it) stores no shell; the warning names the
|
|
609
|
+
deadline. Make it cheaper (`cache()`/`"use cache"`), raise the budget, or move
|
|
610
|
+
its data into a live loader read under a boundary.
|
|
456
611
|
|
|
457
612
|
### The loader lane rule
|
|
458
613
|
|
|
@@ -462,20 +617,36 @@ settled non-promise values are frozen into the shell (snapshot-pinned per
|
|
|
462
617
|
shell). Any promise inside the returned data is masked at capture and stays a
|
|
463
618
|
live hole, streamed fresh on every request at the consumer's own `<Suspense>`,
|
|
464
619
|
however fast it settles. The shape of the return value declares what is live:
|
|
465
|
-
a plain value bakes, a promise stays live.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
620
|
+
a plain value bakes, a promise stays live. (The lane rule is about loaders the
|
|
621
|
+
route registers. A loader a HANDLER awaits with `ctx.use()` is handler output:
|
|
622
|
+
the handler's copy bakes whatever the flag says, even while the same loader's
|
|
623
|
+
registered read stays a live hole.)
|
|
624
|
+
|
|
625
|
+
- **Any depth, plain containers and JSX props.** The mask walks plain objects
|
|
626
|
+
(prototype `Object.prototype` or `null`), arrays and the props of React
|
|
627
|
+
elements at any depth — `{ items: [{ stock: fetchStock(sku) }] }` keeps
|
|
628
|
+
every `stock` live, and so does `{ reviews: <Reviews data={fetchReviews(id)} /> }`
|
|
629
|
+
for `data`. JSX without promises bakes like any plain value. A promise in
|
|
630
|
+
the props of a host element (`<p>`, `<div>`), `<Suspense>`/`<Fragment>` or a
|
|
631
|
+
client component is the hole and nothing else: the element's other props
|
|
632
|
+
bake and stay pinned on every HIT. That includes client components in JSX
|
|
633
|
+
the loader read back from `cache()` or `"use cache"`, which come back
|
|
634
|
+
wrapped in `lazy`. A server component (a function component, `memo` or
|
|
635
|
+
`forwardRef` around one, or a `lazy` that resolves to one) with a promise
|
|
636
|
+
anywhere in its props is the exception: the whole element is the hole and
|
|
637
|
+
renders from the
|
|
638
|
+
fresh loader run on a HIT, so the props it renders into the shell must come
|
|
639
|
+
out the same on every run. A `Map`, `Set`, class instance, or any other
|
|
640
|
+
non-plain object is a LEAF: a promise inside it is NOT masked and does NOT
|
|
641
|
+
become a live hole. Keep live promises in plain objects, arrays and JSX
|
|
642
|
+
props.
|
|
473
643
|
- **The consumer's `<Suspense>` is the hole.** A client component reads the
|
|
474
644
|
live property with `use(data.price)` inside its own `<Suspense>`; that
|
|
475
645
|
boundary postpones at capture and resumes with the fresh value.
|
|
476
|
-
- **
|
|
477
|
-
same mask to
|
|
478
|
-
|
|
646
|
+
- **Loader handle pushes follow the same shape rule.** The capture applies the
|
|
647
|
+
same mask to handle containers a loader pushes, so
|
|
648
|
+
`ctx.use(Handle)({ ..., x: promise })` inside a loader keeps `x` live. The
|
|
649
|
+
same push from a HANDLER bakes `x` (see "Handles").
|
|
479
650
|
|
|
480
651
|
**Every loader without `ssr: false` is entirely live**, whether or not it has
|
|
481
652
|
`loading()`: masked at capture with a never-resolving promise, postponed at its
|
|
@@ -536,29 +707,30 @@ own takes the entire entry — baked `name`/`description` included — into that
|
|
|
536
707
|
hole.
|
|
537
708
|
|
|
538
709
|
**`loading()` is NOT the lane switch and NOT the gate for holes** — it is one
|
|
539
|
-
of the two boundary kinds a live loader postpones at
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
on pure promise/Suspense holes.
|
|
710
|
+
of the two boundary kinds a live loader postpones at; an inline `<Suspense>`
|
|
711
|
+
above the reader is the other. A route with no loader has no holes: its whole
|
|
712
|
+
page is shell, which is a valid ppr route (the shell is served instantly and
|
|
713
|
+
recaptured on TTL/SWR or tag invalidation).
|
|
544
714
|
|
|
545
|
-
The
|
|
715
|
+
The promise positions, side by side:
|
|
546
716
|
|
|
547
717
|
```typescript
|
|
548
718
|
async function Handler(ctx: HandlerContext) {
|
|
549
719
|
const push = ctx.use(MyHandle);
|
|
550
720
|
|
|
551
|
-
push(fetchBadge());
|
|
552
|
-
push({ label: "x", stat: fetchStat() }); //
|
|
553
|
-
// stat streams → HOLE (consumer Suspends it)
|
|
721
|
+
push(fetchBadge()); // top-level handler push: awaited at capture → BAKED
|
|
722
|
+
push({ label: "x", stat: fetchStat() }); // nested in a handler push: awaited at capture → BAKED
|
|
554
723
|
|
|
555
|
-
const data = await fetchHeader(ctx);
|
|
724
|
+
const data = await fetchHeader(ctx); // awaited by the handler → BAKED
|
|
556
725
|
|
|
557
726
|
return (
|
|
558
727
|
<section>
|
|
559
|
-
<Header data={data} />
|
|
560
|
-
<StatsPanel promise={fetchStats(ctx)} />
|
|
561
|
-
|
|
728
|
+
<Header data={data} /> {/* shell */}
|
|
729
|
+
<StatsPanel promise={fetchStats(ctx)} /> {/* un-awaited prop under the consumer's
|
|
730
|
+
<Suspense>: awaited at capture → BAKED */}
|
|
731
|
+
<LiveStats /> {/* "use client": useLoader(StatsLoader)
|
|
732
|
+
under <Suspense>, StatsLoader registered
|
|
733
|
+
without ssr: false → HOLE */}
|
|
562
734
|
</section>
|
|
563
735
|
);
|
|
564
736
|
}
|
|
@@ -566,44 +738,45 @@ async function Handler(ctx: HandlerContext) {
|
|
|
566
738
|
|
|
567
739
|
### Choosing the hole mechanism
|
|
568
740
|
|
|
569
|
-
| Your live region is… | Use
|
|
570
|
-
| ----------------------------------------------- |
|
|
571
|
-
|
|
|
572
|
-
| loader data, shell container + live parts | `loader(Def, { ssr: false })` (the bake lane): `{ static, dynamic: promise }`
|
|
573
|
-
| handler-fetched
|
|
574
|
-
|
|
|
575
|
-
| already-resolved / instant / synchronous values | `loader(() => Promise.resolve(x))` (no `ssr: false`) + a boundary
|
|
576
|
-
| none of the above | nothing
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
741
|
+
| Your live region is… | Use | Why |
|
|
742
|
+
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
743
|
+
| data that must be fresh EVERY serve | `loader()` (the live lane) + `useLoader` under `loading()` or an inline `<Suspense>` | the guaranteed hole — masked at capture, fresh every serve, immune to fast resolution |
|
|
744
|
+
| loader data, shell container + live parts | `loader(Def, { ssr: false })` (the bake lane): `{ static, dynamic: promise }` | plain values bake (snapshot-pinned per shell); nested promises hole at the consumer's `<Suspense>` |
|
|
745
|
+
| handler-fetched data (db, fetch) | nothing to choose: it bakes, whether the handler awaits it or passes the promise down | handler output is shell material; move the fetch into a live-lane loader to make it live |
|
|
746
|
+
| handle metadata that must be live | push it from a loader: a live-lane loader pushes per request; a bake-lane loader's nested promise stays a hole | handler pushes bake at any depth; loader pushes keep "nesting = liveness" |
|
|
747
|
+
| already-resolved / instant / synchronous values | `loader(() => Promise.resolve(x))` (no `ssr: false`) + a boundary | live-lane loaders are masked at capture no matter how fast they settle |
|
|
748
|
+
| none of the above | nothing | it bakes — that is what the shell is for |
|
|
749
|
+
|
|
750
|
+
Why a handler promise cannot be a hole: every HIT replays the handler layer the
|
|
751
|
+
capture recorded, and no handler runs, so nothing on the HIT could produce a
|
|
752
|
+
fresh value for it. The capture therefore waits for it and bakes it, exactly as
|
|
753
|
+
`cache()` does. Loader-side holes do not depend on timing either: the capture
|
|
754
|
+
MASKS every promise nested in a bake-lane container regardless of how fast it
|
|
755
|
+
settles (`maskNestedContainerThenables`), so the consuming boundary always
|
|
756
|
+
postpones and every HIT streams the FRESH value — the promise SHAPE is the
|
|
757
|
+
liveness declaration, not a bet on latency. (Before the mask, a nested promise
|
|
758
|
+
that settled inside the capture window pinned its capture-time value into the
|
|
759
|
+
shared shell; found live as a storefront basket — with the capturing session's
|
|
760
|
+
identifiers — served to anonymous visitors.)
|
|
761
|
+
|
|
762
|
+
### Handles: handler pushes bake; loader pushes keep "nesting = liveness"
|
|
763
|
+
|
|
764
|
+
- `ctx.use(H)(promise)` from a handler — a TOP-LEVEL pushed promise is awaited
|
|
765
|
+
at capture and BAKED into the shell (bounded by `ppr.captureTimeout`, 15s by
|
|
766
|
+
default).
|
|
767
|
+
- `ctx.use(H)({ x: promise })` from a HANDLER — also baked. The capture waits
|
|
768
|
+
for every promise nested in a handler's push, at any depth of plain objects,
|
|
769
|
+
arrays and JSX props, before it records the handles every HIT replays. Keep
|
|
770
|
+
promises in plain objects, arrays and JSX props: one inside a `Map`, `Set`,
|
|
771
|
+
or class instance is not waited for, and if it has not settled when the handles are encoded the
|
|
772
|
+
capture is refused.
|
|
773
|
+
- `ctx.use(H)({ x: promise })` from a LOADER — nesting = liveness. A bake-lane
|
|
774
|
+
(`ssr: false`) loader's container settles and bakes, while the nested promise
|
|
775
|
+
is masked at capture regardless of settle timing and streams fresh to the
|
|
776
|
+
consumer's `<Suspense>` on every HIT (the same mask as bake-lane loader data,
|
|
777
|
+
at any depth of plain objects, arrays and JSX props; a promise inside a
|
|
778
|
+
`Map`, `Set`, or class instance is not masked). A live-lane
|
|
779
|
+
loader never runs at capture, so all of its pushes happen per request.
|
|
607
780
|
|
|
608
781
|
### Want a hole for already-resolved data?
|
|
609
782
|
|
|
@@ -621,8 +794,9 @@ non-promise data bakes into the prelude; every promise nested in it is masked
|
|
|
621
794
|
at capture (regardless of how fast it settles) and postpones at the consumer's
|
|
622
795
|
own `<Suspense>` — a hole. The capture records the container into the shell
|
|
623
796
|
snapshot's loader family so every HIT payload matches the frozen prelude
|
|
624
|
-
|
|
625
|
-
|
|
797
|
+
outside the holes (see "On a shell HIT" below; a server component holding a
|
|
798
|
+
promise is the one element that is a hole as a whole, see "Any depth" above).
|
|
799
|
+
The return shape is the declaration:
|
|
626
800
|
|
|
627
801
|
```typescript
|
|
628
802
|
export const StorefrontContextLoader = createLoader(async (ctx) => {
|
|
@@ -646,43 +820,63 @@ entries, not just routes.
|
|
|
646
820
|
|
|
647
821
|
#### On a shell HIT
|
|
648
822
|
|
|
649
|
-
What a bake-lane loader does on a
|
|
650
|
-
container carried holes
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
823
|
+
What a bake-lane loader does on a HIT depends on whether its recorded
|
|
824
|
+
container carried holes. A client navigation that replays a shell captured by
|
|
825
|
+
a document request (`x-rango-ppr-replay: HIT`) does the same, for every
|
|
826
|
+
`ssr: false` loader, including one on an entry with `loading()` (before, a
|
|
827
|
+
navigation ran every loader and served its fresh values). A snapshot captured
|
|
828
|
+
by a navigation alone carries no pins, and its replay runs these loaders fresh.
|
|
829
|
+
|
|
830
|
+
- **Hole-free record (the return had no promises): served from the shell.**
|
|
831
|
+
The response uses the pinned container immediately and the loader body does
|
|
832
|
+
NOT run (unless the capture marked it to run: see the handle pushes note
|
|
833
|
+
below): a HIT is rendered from the shell, like the handlers it replays, so
|
|
834
|
+
the loader costs nothing per HIT. Side effects in its body happen once per
|
|
835
|
+
capture, not per request. The output changes only when the shell is
|
|
659
836
|
recaptured (TTL/SWR expiry or tag invalidation).
|
|
660
|
-
- **Hole-carrying record (the return had promises).** The loader runs
|
|
661
|
-
the critical path — only the body can create the live promises
|
|
662
|
-
recorded baked paths are overlaid onto the fresh
|
|
663
|
-
matches the prelude while the nested promises stream
|
|
664
|
-
rejection skips the overlay and goes to the loader's error
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
837
|
+
- **Hole-carrying record (the return had promises).** The loader runs on every
|
|
838
|
+
HIT, ON the critical path — only the body can create the live promises that
|
|
839
|
+
fill the holes — and the recorded baked paths are overlaid onto the fresh
|
|
840
|
+
result, so the payload matches the prelude while the nested promises stream
|
|
841
|
+
fresh. A fresh rejection skips the overlay and goes to the loader's error
|
|
842
|
+
boundary. Give it its own cache,
|
|
843
|
+
`loader(Def, { ssr: false }, () => [cache({ ttl })])`, so that run reads
|
|
844
|
+
through the loader cache.
|
|
845
|
+
|
|
846
|
+
Whether a return "has promises" is decided ONCE, at capture, by the shape of
|
|
847
|
+
the value, never by timing: `maskNestedContainerThenables`
|
|
848
|
+
(`router/segment-resolution/mask-nested.ts`) walks the returned data through
|
|
849
|
+
plain objects, arrays and JSX element props and turns every thenable into a
|
|
850
|
+
hole; the drain stores the result as the record's `holes` bit. A promise that
|
|
851
|
+
resolves in 1 ms is still a hole, so `{ product: await getProduct() }` bakes
|
|
852
|
+
and does not run on a HIT, while `{ product: getProduct() }` is a hole and
|
|
853
|
+
runs on every HIT. A promise inside a `Map`, `Set` or class instance is not
|
|
854
|
+
walked and is not a hole: the capture's record encode waits for it and bakes
|
|
855
|
+
its settled value, and a HIT serves that value without running the loader.
|
|
856
|
+
|
|
857
|
+
The granularity is the WHOLE loader: a bake-lane loader returning
|
|
858
|
+
`{ product, reviews: promise }` runs its entire body on every HIT, the product
|
|
859
|
+
fetch included, even though the captured product overlays its result. Split
|
|
860
|
+
it into a promise-free `ssr: false` loader plus a live loader for the
|
|
861
|
+
per-request part, or give it its own `cache()` so that run reads through it:
|
|
862
|
+
|
|
863
|
+
```tsx
|
|
864
|
+
loader(ProductLoader, { ssr: false }), // promise-free: baked, not run on a HIT
|
|
865
|
+
loader(ReviewsLoader), // live: the hole, under loading()
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
**Handle pushes from a bake-lane loader appear once.** The capture records
|
|
869
|
+
the settled, thenable-free handle pushes of every loader body it runs (the
|
|
870
|
+
prelude rendered them): the `ssr: false` loader's own, those of the loaders
|
|
871
|
+
it awaits with `ctx.use()`, and those its own `cache()` entry replays. Every HIT restores them with the handler layer. A
|
|
872
|
+
loader that does run on the HIT (a hole-carrying bake-lane loader, or a live
|
|
873
|
+
loader awaiting the same loader) replaces its restored pushes in place, so
|
|
874
|
+
any handle, deduping or not, shows each value once; a push that lands after
|
|
875
|
+
the document's handle snapshot reaches the client after hydration. A push the
|
|
876
|
+
capture cannot record (a deferred push, or one holding a promise) marks the
|
|
877
|
+
loader records to run: those
|
|
878
|
+
bodies then still run on each HIT, in the background, so the push reaches the
|
|
879
|
+
page.
|
|
686
880
|
|
|
687
881
|
Four hard edges (each e2e/unit-pinned):
|
|
688
882
|
|
|
@@ -691,10 +885,10 @@ Four hard edges (each e2e/unit-pinned):
|
|
|
691
885
|
or loader on a ppr route calling `ctx.headers.set()`, `cookies().set()`,
|
|
692
886
|
`ctx.setTheme()`, or the request-context `header()`/`setStatus()` throws on
|
|
693
887
|
EVERY render — dev and prod, first render, same guard family as the
|
|
694
|
-
`cache()` boundary guard.
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
888
|
+
`cache()` boundary guard. Handler output is replayed on HITs and no handler
|
|
889
|
+
runs there (the write would silently differ between MISS and HIT); loaders
|
|
890
|
+
are live but settle AFTER the response headers flushed with the shell (dead
|
|
891
|
+
letters). Move the write into route middleware — it runs
|
|
698
892
|
on every request, including HITs, and its headers/cookies merge into every
|
|
699
893
|
response. The one exception: a handler that calls `ctx.dynamic()` FIRST
|
|
700
894
|
re-permits its own header/cookie write (#735) — a dynamic() render never
|
|
@@ -705,10 +899,17 @@ Four hard edges (each e2e/unit-pinned):
|
|
|
705
899
|
`ssr: false` flag (the live lane is exempt; give it a boundary) or move the
|
|
706
900
|
identity-dependent part into a separate loader without `ssr: false`. A
|
|
707
901
|
nested promise does not help here: its body still runs during capture and
|
|
708
|
-
trips the guard. The
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
902
|
+
trips the guard. The same refusal covers everything else the capture waits
|
|
903
|
+
for (a handler, a promise it passes or pushes, an async server component, a
|
|
904
|
+
loader a handler awaits), a `{ cache: false }` variable
|
|
905
|
+
(`createVar({ cache: false })` or `ctx.set(..., { cache: false })`) read
|
|
906
|
+
there, and the visitor's theme (`ctx.theme`, `getRequestContext().theme`,
|
|
907
|
+
#971); see "Security". Read the theme with `useTheme()` in a client
|
|
908
|
+
component, or in a live loader with `cookies().get("theme")`; the shell's
|
|
909
|
+
`initialTheme` is the no-cookie default. Per-user state read from a NORMAL
|
|
910
|
+
middleware-provided variable (`ctx.get("session")`) does NOT refuse — it
|
|
911
|
+
bakes silently as the capturing user's data (see Pitfalls: the
|
|
912
|
+
session-object bake trap).
|
|
712
913
|
- **A rejecting bake-lane loader refuses.** Error UI never bakes. So does a
|
|
713
914
|
value that fails to encode: a function, a class instance, a promise inside a
|
|
714
915
|
`Map` that rejects, or a server component in the value that throws. The
|
|
@@ -718,10 +919,11 @@ Four hard edges (each e2e/unit-pinned):
|
|
|
718
919
|
that throws only on that run refuses it too. A build-time capture skips the
|
|
719
920
|
shell (`SHELL SKIP`) and the route keeps runtime capture.
|
|
720
921
|
- **Baked containers show CAPTURE-time data** for the shell's lifetime on
|
|
721
|
-
document GETs
|
|
722
|
-
|
|
723
|
-
lane's meaning; if a value
|
|
724
|
-
live lane (no `ssr: false`) or
|
|
922
|
+
document GETs, and on soft navigations that replay a shell captured by a
|
|
923
|
+
document request (`x-rango-ppr-replay: HIT`). Live loaders and their
|
|
924
|
+
item/response reads remain fresh. That IS the bake lane's meaning; if a value
|
|
925
|
+
must be fresh on every serve, it belongs on the live lane (no `ssr: false`) or
|
|
926
|
+
in a nested promise.
|
|
725
927
|
|
|
726
928
|
### The layout-with-loaders playbook (the storefront case)
|
|
727
929
|
|
|
@@ -779,46 +981,51 @@ their data should bake vs stay live. Your levers, in order of preference:
|
|
|
779
981
|
GUARANTEED fresh per serve — use this where the bake lane's pinning
|
|
780
982
|
(capture-time data for the shell's lifetime) is not acceptable, at the cost
|
|
781
983
|
of a widget-sized fallback in the shell. The slot handler must hand the
|
|
782
|
-
loader to a CLIENT component (`useLoader` in a `"use client"` component)
|
|
783
|
-
|
|
784
|
-
`await ctx.use(
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
4. **Shared layout data
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
`cookies()`/`headers()`
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
handler
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
984
|
+
loader to a CLIENT component (`useLoader` in a `"use client"` component):
|
|
985
|
+
that client-side read is the hole. A server-side
|
|
986
|
+
`await ctx.use(WishlistLoader)` in the slot handler is handler output: it
|
|
987
|
+
runs at capture, its value bakes into the shell for every visitor, and if
|
|
988
|
+
the loader reads `cookies()`/`headers()` (the usual case for a per-user
|
|
989
|
+
loader) the capture is REFUSED and the page stays on MISS.
|
|
990
|
+
|
|
991
|
+
4. **Shared layout data does not need a loader at all**: render it from the
|
|
992
|
+
handler (awaited, passed down as a promise, or pushed — it all bakes) and
|
|
993
|
+
wrap the expensive part in `cache()`/`"use cache"` so captures stay cheap
|
|
994
|
+
and the shell is tag-invalidatable.
|
|
995
|
+
|
|
996
|
+
The identity rule, stated once: per-user data on a PPR page lives in a
|
|
997
|
+
live-lane loader (no `ssr: false`) consumed CLIENT-side with `useLoader` under
|
|
998
|
+
`loading()` or an inline `<Suspense>`, or in a NESTED promise inside a
|
|
999
|
+
bake-lane loader (a hole, fresh per request). A nested promise's body still
|
|
1000
|
+
runs at capture, so it must not call `cookies()`/`headers()` itself — identity
|
|
1001
|
+
reads belong in the live-lane loader. Reading `cookies()`, `headers()`, or a
|
|
1002
|
+
`{ cache: false }` variable anywhere the capture waits for refuses the capture
|
|
1003
|
+
by construction: handler/render code, a promise the handler passes or pushes,
|
|
1004
|
+
an async server component, a bake-lane loader, and a loader a handler awaits
|
|
1005
|
+
(`await ctx.use(Loader)`). There is no exemption for handler-invoked loaders:
|
|
1006
|
+
every HIT replays the capture's copy of their value, so an identity read there
|
|
1007
|
+
would show the capturing request's user to every visitor.
|
|
805
1008
|
|
|
806
1009
|
### Designing routes for cheap captures (the cost model)
|
|
807
1010
|
|
|
808
1011
|
The hole doctrine has a cost corollary that bites silently: **everything that
|
|
809
1012
|
bakes is awaited at capture, and that wait recurs on EVERY capture of the
|
|
810
|
-
route**.
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
1013
|
+
route**. That now includes every promise a handler produces: a prop promise, an
|
|
1014
|
+
async server component's data, a nested value in a handle push, a loader the
|
|
1015
|
+
handler awaits. A handler pushing a handle promise that takes 5s and a Meta
|
|
1016
|
+
promise chained 2s further make every capture occupy the per-isolate serialized
|
|
1017
|
+
queue for ~7s — while the served response still reads 13ms TTFB, because
|
|
1018
|
+
captures are detached. You will not see this cost in any request timing; you
|
|
1019
|
+
see it as slow MISS→HIT flips, `skip-queue-timeout` under prefetch pressure,
|
|
1020
|
+
and (in dev, past 2s) the bake-cost warning naming the source.
|
|
816
1021
|
|
|
817
1022
|
Three levers, in preference order:
|
|
818
1023
|
|
|
819
|
-
1. **
|
|
820
|
-
|
|
821
|
-
capture cost.
|
|
1024
|
+
1. **Make it live**: move the value into a live-lane loader (no `ssr: false`)
|
|
1025
|
+
read with `useLoader` under `loading()` or an inline `<Suspense>` — a hole,
|
|
1026
|
+
per request, zero capture cost. Inside a bake-lane loader, return the slow
|
|
1027
|
+
part as a nested promise instead. Nesting a promise inside a HANDLER's push
|
|
1028
|
+
or props no longer does this: handler output is always awaited.
|
|
822
1029
|
2. **`cache()` the work inside it**: the value stays baked (shell material,
|
|
823
1030
|
tag-invalidatable), but the capture replays the cached value instead of
|
|
824
1031
|
re-executing the expensive body (mixed-chain). Choose this for shared,
|
|
@@ -829,8 +1036,9 @@ Three levers, in preference order:
|
|
|
829
1036
|
reader).
|
|
830
1037
|
|
|
831
1038
|
Head material (Meta) pushed by HANDLERS cannot be a hole — the head is shell —
|
|
832
|
-
so those promises bake by design; make them cheap with lever 2.
|
|
833
|
-
on the capture debug event
|
|
1039
|
+
so those promises bake by design; make them cheap with lever 2.
|
|
1040
|
+
`recordSettleMs` and `bakeWaitMs` on the capture debug event tell you what each
|
|
1041
|
+
capture actually paid. A
|
|
834
1042
|
Meta pushed by a LIVE-lane loader is different: those loaders are masked at
|
|
835
1043
|
capture, so the push happens at request time and applies client-side
|
|
836
1044
|
(`metadata.handlesLate`) — it is never in the cached shell's head, by
|
|
@@ -838,25 +1046,29 @@ construction. A bake-lane (`ssr: false`) loader executes at capture, so its
|
|
|
838
1046
|
settled pushes are shell material like a handler's.
|
|
839
1047
|
|
|
840
1048
|
`loader(Def, { ssr: false })` (the document-render await, `/loader`) is the
|
|
841
|
-
bake-lane switch under PPR, not
|
|
842
|
-
the flagged loader too, so its settled non-promise data — handle
|
|
843
|
-
included — freezes into the stored shell and recurs as capture cost on
|
|
844
|
-
capture (levers 1 and 2 apply to it).
|
|
845
|
-
|
|
846
|
-
navigations stream it.
|
|
1049
|
+
bake-lane switch under PPR, not a knob for normal renders only: the capture
|
|
1050
|
+
render awaits the flagged loader too, so its settled non-promise data — handle
|
|
1051
|
+
pushes included — freezes into the stored shell and recurs as capture cost on
|
|
1052
|
+
every capture (levers 1 and 2 apply to it). On a MISS the flag keeps its
|
|
1053
|
+
normal-render meaning: document renders await it before first flush, client
|
|
1054
|
+
navigations stream it. A shell HIT, and a navigation that replays a shell
|
|
1055
|
+
captured by a document request, serve a promise-free one from the shell
|
|
1056
|
+
without running it (unless the capture marked it to run: see "On a shell
|
|
1057
|
+
HIT"); a snapshot captured by a navigation alone carries no pins, and its
|
|
1058
|
+
replay runs it fresh.
|
|
847
1059
|
|
|
848
1060
|
## Execution matrix
|
|
849
1061
|
|
|
850
|
-
| Phase | MISS (foreground) | Background capture
|
|
851
|
-
| ---------------- | ---------------------- |
|
|
852
|
-
| Middleware chain | runs (full) | **NOT re-run** — inherits the request's post-middleware context
|
|
853
|
-
| `router.match` | runs | re-runs under a derived context
|
|
854
|
-
| Handlers | run | run on UNCACHED segments
|
|
855
|
-
| Loaders | run **fresh** | LIVE lane (no `ssr: false`): MASKED; BAKE lane (`ssr: false`): execute + snapshot-pin
|
|
856
|
-
| Flight render | full | full
|
|
857
|
-
| HTML production | full fizz | `prerender` + abort → prelude + postponed
|
|
858
|
-
| Shell store | schedules a bg capture | `putShell(key, …)`
|
|
859
|
-
| Prelude bytes | — | —
|
|
1062
|
+
| Phase | MISS (foreground) | Background capture | HIT (foreground) |
|
|
1063
|
+
| ---------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
1064
|
+
| Middleware chain | runs (full) | **NOT re-run** — inherits the request's post-middleware context | runs (full) — commit point is after it |
|
|
1065
|
+
| `router.match` | runs | re-runs under a derived context | runs (behind the flushed prelude) |
|
|
1066
|
+
| Handlers | run | run on UNCACHED segments (`cache()`d segments replay); everything they produce — promises, async server components, handle pushes, awaited loaders — settles before the freeze (`ppr.captureTimeout`) | **never run** — the handler layer is replayed from the shell's recorded segments |
|
|
1067
|
+
| Loaders | run **fresh** | LIVE lane (no `ssr: false`): MASKED; BAKE lane (`ssr: false`): execute + snapshot-pin | live: run **fresh**; bake: pinned, runs only if its record has holes |
|
|
1068
|
+
| Flight render | full | full, from the capture's own recorded segments (the same bytes every HIT replays) | full (hydration needs the whole payload — no Flight resume) |
|
|
1069
|
+
| HTML production | full fizz | `prerender` + abort → prelude + postponed | `resume` only the holes — O(paths to holes) |
|
|
1070
|
+
| Shell store | schedules a bg capture | `putShell(key, …)` | `getShell(key)`; a stale/SWR hit also schedules a recapture |
|
|
1071
|
+
| Prelude bytes | — | — | flushed FIRST, before segment resolution starts |
|
|
860
1072
|
|
|
861
1073
|
Middleware is not re-run during capture because it already ran for the
|
|
862
1074
|
triggering request — the capture's derived context inherits the
|
|
@@ -864,52 +1076,66 @@ post-middleware state (`ctx` variables included, which is what makes
|
|
|
864
1076
|
middleware-derived shell content photograph correctly). Guarding is
|
|
865
1077
|
serve-time: the commit point runs the full chain on EVERY serve.
|
|
866
1078
|
|
|
867
|
-
Because handlers on uncached segments EXECUTE during capture —
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
1079
|
+
Because handlers on uncached segments EXECUTE during capture — along with
|
|
1080
|
+
everything they produce and every BAKE-lane loader — the capture guard is
|
|
1081
|
+
load-bearing: `cookies()`, `headers()`, a theme read, and a `{ cache: false }`
|
|
1082
|
+
variable read THROW during a capture render, and the capture
|
|
1083
|
+
is refused even when the code catches that throw, so identity can never leak
|
|
1084
|
+
into a shared shell through them. Live-lane loaders (every loader without
|
|
1085
|
+
`ssr: false`) are exempt: masked at capture, they never run there.
|
|
873
1086
|
|
|
874
1087
|
## allReady: the SEO/bot story
|
|
875
1088
|
|
|
876
1089
|
`ssr: { resolveStreaming: ... }` returning `"allReady"` (e.g. for bot user
|
|
877
1090
|
agents) bypasses PPR entirely — the request gets one complete, fully-buffered
|
|
878
|
-
|
|
879
|
-
regular users get the streamed shell. No configuration
|
|
880
|
-
wins.
|
|
1091
|
+
document (a normal render, no shell). Crawlers that dislike streamed shells
|
|
1092
|
+
get a finished page; regular users get the streamed shell. No configuration
|
|
1093
|
+
interaction: allReady wins.
|
|
881
1094
|
|
|
882
1095
|
## Security
|
|
883
1096
|
|
|
884
|
-
Shell caching shares one shell per host+URL
|
|
1097
|
+
Shell caching shares one shell per host+URL (and request partition, see
|
|
1098
|
+
"Request-partitioned shells") across all users:
|
|
885
1099
|
|
|
886
1100
|
**(a) Access control is sound by construction.** The commit point is after ALL
|
|
887
1101
|
middleware on every serve. A 401/redirect short-circuit returns before any
|
|
888
1102
|
shell byte.
|
|
889
1103
|
|
|
890
|
-
**(b)
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
1104
|
+
**(b) Request-scoped reads refuse the capture.** During the background capture
|
|
1105
|
+
render, `cookies()`, `headers()`, the visitor's theme (`ctx.theme`,
|
|
1106
|
+
`getRequestContext().theme`), and `ctx.get()` of a `{ cache: false }` variable
|
|
1107
|
+
(`createVar({ cache: false })`, or a value written with
|
|
1108
|
+
`ctx.set(..., { cache: false })`) THROW, wherever the capture waits for them:
|
|
1109
|
+
a handler, a promise it passes or pushes, an async server component, a
|
|
1110
|
+
bake-lane loader, and a loader a handler awaits (`await ctx.use(Loader)`). The
|
|
1111
|
+
capture is refused even if your code catches the throw, and the route keeps
|
|
1112
|
+
serving MISSes with a once-per-key warning. `ctx.dynamic()` called there
|
|
1113
|
+
refuses it too. The live lane (no `ssr: false`) stays exempt: masked at capture, it never
|
|
1114
|
+
runs there.
|
|
1115
|
+
|
|
1116
|
+
**(c) Residual hazard — middleware-derived per-user state.** A NORMAL `ctx`
|
|
1117
|
+
variable (no `cache: false`) set by an upstream auth middleware and rendered by
|
|
1118
|
+
shell material is photographed into the SHARED shell (the capture inherits
|
|
1119
|
+
post-middleware state), and so is a raw `ctx.request.headers` read. The guard
|
|
1120
|
+
cannot see either. That is scope fidelity working as designed — for shared
|
|
1121
|
+
values. It reaches handlers and BAKE-LANE LOADERS alike: a loader reading a
|
|
1122
|
+
middleware-provided session object (`ctx.get("session")`) never calls
|
|
1123
|
+
`cookies()` itself, so whatever it returns as settled container data is
|
|
1124
|
+
photographed as the CAPTURING user's state. If the value is per-user:
|
|
1125
|
+
shell-cache only public/shared pages, keep per-user content in live-lane
|
|
1126
|
+
loaders (no `ssr: false`) or nested promises in bake-lane loader data — NOT in
|
|
1127
|
+
handler output or plain bake-lane container data — mark the variable
|
|
1128
|
+
`{ cache: false }` so a stray shell read refuses the capture, or key per
|
|
1129
|
+
variant at the CDN tier.
|
|
1130
|
+
|
|
1131
|
+
## What always renders without a shell
|
|
908
1132
|
|
|
909
1133
|
Non-GET, non-partial RSC/action/loader fetches, partial requests without an
|
|
910
1134
|
eligible captured segment snapshot, per-request CSP nonce, `streamMode:
|
|
911
|
-
"allReady"`, redirects, 404s, error renders, routes without `ppr`,
|
|
912
|
-
|
|
1135
|
+
"allReady"`, redirects, 404s, error renders, routes without `ppr`, a document
|
|
1136
|
+
request the route's own `cache()` scope refuses (`cache(false)`, or a
|
|
1137
|
+
`condition()` returning false for it), and any store without the shell family.
|
|
1138
|
+
A stored shell is invalidated when
|
|
913
1139
|
`React.version` changes (postponed state is build-coupled), so deploys
|
|
914
1140
|
self-heal via recapture.
|
|
915
1141
|
|
|
@@ -926,8 +1152,8 @@ point (which runs after the whole middleware chain), so a middleware-set nonce
|
|
|
926
1152
|
blocks capture the same as a provider one. Because the route DECLARED `ppr`
|
|
927
1153
|
but cannot be honored, it logs a once-per-key worker warning (same
|
|
928
1154
|
declared-intent-cannot-be-honored doctrine as the missing-store warning) and
|
|
929
|
-
serves
|
|
930
|
-
silent.
|
|
1155
|
+
serves a normal render (no shell) with no `x-rango-shell` header. An
|
|
1156
|
+
undeclared route stays silent.
|
|
931
1157
|
|
|
932
1158
|
### The proper way to supply a nonce
|
|
933
1159
|
|
|
@@ -957,13 +1183,38 @@ path(
|
|
|
957
1183
|
);
|
|
958
1184
|
```
|
|
959
1185
|
|
|
960
|
-
| Field | Default | Notes
|
|
961
|
-
| ------------------ | ------- |
|
|
962
|
-
| `ttl` | `300` | shell freshness window in seconds (`ppr: true` uses the default)
|
|
963
|
-
| `swr` | — | stale window: serve the stale shell + background recapture
|
|
964
|
-
| `tags` | — | operational tags UNIONED with the tags the capture
|
|
965
|
-
| `maxSnapshotBytes` | 8 MiB | cap on the entry's
|
|
966
|
-
| `captureTimeout` | 15000ms | capture
|
|
1186
|
+
| Field | Default | Notes |
|
|
1187
|
+
| ------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1188
|
+
| `ttl` | `300` | shell freshness window in seconds (`ppr: true` uses the default) |
|
|
1189
|
+
| `swr` | — | stale window: serve the stale shell + background recapture |
|
|
1190
|
+
| `tags` | — | operational tags UNIONED with the tags the capture collects — see "Invalidation" below |
|
|
1191
|
+
| `maxSnapshotBytes` | 8 MiB | cap on the loader pins in the entry's snapshot (bake-lane loader records and the cached items/responses those loaders read). The recorded handler layer is exempt. Over the cap the pins are dropped and the shell is stored with its handler layer (warned once per key); bake-lane loaders then read the live store, and drift is repaired client-side |
|
|
1192
|
+
| `captureTimeout` | 15000ms | ONE capture deadline: the handler layer settling (promises it passes or pushes, async server components, loaders it awaits), bake-lane loaders, and the prerender; a capture that misses it stores nothing rather than a partial shell |
|
|
1193
|
+
|
|
1194
|
+
A shell never outlives the route `cache()` entry it was captured from: under
|
|
1195
|
+
a route `cache()`, the shell is fresh no longer than that entry is (at most
|
|
1196
|
+
`ppr.ttl`) and served no longer than that entry can be (at most `ppr.ttl` +
|
|
1197
|
+
`ppr.swr`), so a document HIT and a client navigation (which reads the
|
|
1198
|
+
`cache()` entry first) show the same handler output. An entry already in its
|
|
1199
|
+
`swr` window gives a shell that is stale from the start, served while it
|
|
1200
|
+
recaptures. Each isolate recaptures a stale shell at most once per second
|
|
1201
|
+
(`SHELL_MIN_RECAPTURE_INTERVAL_MS`): a HIT within a second of the shell's
|
|
1202
|
+
capture serves it without starting another. When the entry a capture read
|
|
1203
|
+
runs out before the store (it was near its end), the capture retries once on
|
|
1204
|
+
a fresh match. Nothing is stored when the retry's entry runs out too, when
|
|
1205
|
+
the capture budget leaves no time to retry, or when the capture wrote the
|
|
1206
|
+
entry itself and it ran out before the store (its `ttl` + `swr` is no longer
|
|
1207
|
+
than the rest of the capture): the URL backs off, and a warning names the
|
|
1208
|
+
route and the entry's `ttl`/`swr`, once per route (dev and production). In dev an explicit `ppr.ttl`/`ppr.swr` the entry reduces
|
|
1209
|
+
warns once per route, stating what the shell is stored with; with no `ppr`
|
|
1210
|
+
window set, the cap applies silently.
|
|
1211
|
+
|
|
1212
|
+
Separately from `maxSnapshotBytes`, the whole entry (prelude, postponed state,
|
|
1213
|
+
and snapshot) must fit the store's value limit — 25 MiB by default, Cloudflare
|
|
1214
|
+
KV's; `VercelCacheStore` derives its own from its item cap. A bigger entry
|
|
1215
|
+
refuses the capture (warned once per key) instead of failing the store write:
|
|
1216
|
+
shrink what the shell bakes or move large regions under a live loader's
|
|
1217
|
+
boundary.
|
|
967
1218
|
|
|
968
1219
|
The shell store is always the app-level `createRouter({ cache })` store; the
|
|
969
1220
|
default key is `${host}${pathname}${sortedSearch}:shell` (host-scoped so
|
|
@@ -980,19 +1231,31 @@ output is shared; see `/deployment-caching`.
|
|
|
980
1231
|
`updateTag()`/`revalidateTag()` is the ONLY lever that changes the frozen shell
|
|
981
1232
|
HTML; `revalidate()` is a DATA lever that never touches it.
|
|
982
1233
|
|
|
983
|
-
A captured shell
|
|
984
|
-
|
|
985
|
-
from a `"use cache"` function, a `cache()` segment, or a
|
|
986
|
-
`cacheTag()` in a plain server component (no
|
|
987
|
-
tree)
|
|
988
|
-
capture
|
|
989
|
-
|
|
1234
|
+
A captured shell carries the tags of what renders into it: its segment
|
|
1235
|
+
record's tags — every `cacheTag(...)` the handler layer ran as shell material,
|
|
1236
|
+
whether from a `"use cache"` function, a `cache()` segment, or a
|
|
1237
|
+
render-callable `cacheTag()` in a plain server component (no
|
|
1238
|
+
`"use cache"`/`cache()` in its tree) — plus the tags of loaders on the BAKE
|
|
1239
|
+
lane (they execute during capture and their data is in the shell). A tag
|
|
1240
|
+
recorded outside what the shell renders is not on it. A live-lane loader's tags (every loader without `ssr: false`)
|
|
1241
|
+
attach only when a handler consumes its value with `ctx.use()`, which bakes
|
|
1242
|
+
it; one read only by the client stays off, since it is masked at capture and
|
|
1243
|
+
its hole is already live. `ppr.tags` adds
|
|
990
1244
|
operational tags the render cannot know (a tenant id, a deploy marker).
|
|
991
1245
|
|
|
1246
|
+
When the route has its own `cache()`, the capture replays that record instead
|
|
1247
|
+
of re-rendering, so nothing it covers runs at capture. The record stores the
|
|
1248
|
+
tags its content recorded when the foreground wrote it and re-records them on
|
|
1249
|
+
the HIT, so the shell carries the same union. That includes a `loading()`
|
|
1250
|
+
slot's handler output (a HIT replays it from the record) and any loader a
|
|
1251
|
+
handler consumes with `ctx.use()`; a loader read only by `useLoader()` under
|
|
1252
|
+
`loading()` stays off. `updateTag()` of such a tag drops the record together
|
|
1253
|
+
with the shell, so the recapture renders fresh.
|
|
1254
|
+
|
|
992
1255
|
| Lever | Reaches the frozen shell? | Reaches the holes? |
|
|
993
1256
|
| ------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------- |
|
|
994
1257
|
| `updateTag` / `revalidateTag` on a SHELL tag | YES — drops the shell → MISS → recapture | n/a (holes are already live) |
|
|
995
|
-
| `updateTag` / `revalidateTag` on a live-lane LOADER tag |
|
|
1258
|
+
| `updateTag` / `revalidateTag` on a live-lane LOADER tag | only if a handler consumes the loader (`ctx.use()`) | drops that loader's cached value (if it `cache()`s) |
|
|
996
1259
|
| `revalidate()` (named revalidation contract) | **no** — re-runs segments/loaders for the PAYLOAD, never HTML | yes — the hole re-renders with fresh data |
|
|
997
1260
|
|
|
998
1261
|
A server action's automatic invalidation refreshes the CLIENT only — it re-runs
|
|
@@ -1000,33 +1263,49 @@ the holes and streams a fresh payload, but does NOT evict the server shell.
|
|
|
1000
1263
|
Shell-baked data stays stale until the shell's TTL unless you tag-invalidate it
|
|
1001
1264
|
(`updateTag` on a shell tag). Data baked into the shell WITHOUT a tag cannot be
|
|
1002
1265
|
evicted by tag at all — move always-fresh data into a live-lane loader (no
|
|
1003
|
-
`ssr: false`) or a nested promise.
|
|
1266
|
+
`ssr: false`) or a nested promise in bake-lane loader data.
|
|
1004
1267
|
|
|
1005
1268
|
## Pitfalls
|
|
1006
1269
|
|
|
1007
1270
|
- **A bake-lane loader that reads `cookies()`/`headers()`**: the capture is
|
|
1008
|
-
REFUSED (deterministic, once-per-key warned) — the route
|
|
1009
|
-
Move identity onto the live lane (drop `ssr: false`, or split the read into
|
|
1271
|
+
REFUSED (deterministic, once-per-key warned) — the route keeps serving
|
|
1272
|
+
MISSes. Move identity onto the live lane (drop `ssr: false`, or split the read into
|
|
1010
1273
|
a separate unflagged loader; give the reader a boundary). A nested promise
|
|
1011
1274
|
does not help here: its body still runs during capture.
|
|
1012
1275
|
- **A bake-lane container that must be fresh per document GET**: it is
|
|
1013
1276
|
snapshot-pinned for the shell's lifetime by design. Use the live lane
|
|
1014
1277
|
(no `ssr: false`) or a nested promise instead.
|
|
1015
|
-
- **
|
|
1016
|
-
capture
|
|
1017
|
-
|
|
1278
|
+
- **Handler output or a bake-lane loader slower than `ppr.captureTimeout`
|
|
1279
|
+
(15s by default)**: the capture stores nothing rather than a partial shell
|
|
1280
|
+
(the warning says the output "did not settle within ppr.captureTimeout").
|
|
1281
|
+
Make the slow part cheaper (`cache()`/`"use cache"`), move it into a live
|
|
1282
|
+
loader, or increase the route's budget only when the deployment can keep the
|
|
1283
|
+
background/build work alive.
|
|
1284
|
+
- **A pending handler promise expected to be a hole**: it is not. A promise
|
|
1285
|
+
the handler passes under `<Suspense>`, an async server component, or a
|
|
1286
|
+
promise nested in a handler's handle push is awaited at capture and served
|
|
1287
|
+
frozen on every HIT. Move per-request data into a live-lane loader read with
|
|
1288
|
+
`useLoader` under `loading()` or an inline `<Suspense>` (see "Migration from
|
|
1289
|
+
the old promise-hole model").
|
|
1290
|
+
- **`cache(false)` or a false `condition()` on a ppr route**: the document
|
|
1291
|
+
request renders like a cache miss — a normal render, no `x-rango-shell`
|
|
1292
|
+
header, no capture. A `condition()` that is false only for some requests
|
|
1293
|
+
renders those requests normally (no shell) while the others keep serving the
|
|
1294
|
+
shell.
|
|
1018
1295
|
- **Per-user value in shell material**: baked into the shared shell —
|
|
1019
|
-
deterministically, not by race (handler promises
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1296
|
+
deterministically, not by race (handler output, promises included, is
|
|
1297
|
+
awaited at capture; awaited/resolved values bake everywhere). Put per-user
|
|
1298
|
+
data in a live-lane loader (no `ssr: false`) or a nested promise in
|
|
1299
|
+
bake-lane loader data — plain BAKE-lane loader data bakes just like handler
|
|
1023
1300
|
material.
|
|
1024
1301
|
- **The session-object bake trap (the guard cannot save you here)**: the
|
|
1025
|
-
capture guard sees `cookies()
|
|
1026
|
-
reading a middleware-provided
|
|
1027
|
-
|
|
1302
|
+
capture guard sees `cookies()`, `headers()`, and `{ cache: false }` variable
|
|
1303
|
+
reads ONLY. A handler or bake-lane loader reading a NORMAL middleware-provided
|
|
1304
|
+
session object (`ctx.get("session")`) refuses nothing. Inside a bake-lane
|
|
1305
|
+
loader, per-user data survives ONLY behind a nested promise — the shape is
|
|
1028
1306
|
the declaration, and it holds for BOTH branches regardless of settle timing
|
|
1029
|
-
(nested thenables are masked at capture):
|
|
1307
|
+
(nested thenables are masked at capture). In a handler nothing survives: a
|
|
1308
|
+
handler's output bakes, promises included.
|
|
1030
1309
|
|
|
1031
1310
|
```typescript
|
|
1032
1311
|
const CartLoader = createLoader(async (ctx) => {
|
|
@@ -1042,12 +1321,13 @@ evicted by tag at all — move always-fresh data into a live-lane loader (no
|
|
|
1042
1321
|
(even an already-resolved one) or put the loader on the live lane (drop
|
|
1043
1322
|
`ssr: false`).
|
|
1044
1323
|
|
|
1045
|
-
- **Theme on a HIT is
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
the
|
|
1324
|
+
- **Theme on a HIT is default-then-corrected**: the shell's `initialTheme` is
|
|
1325
|
+
the no-cookie default (`defaultTheme`), whoever captured it, and the resume
|
|
1326
|
+
tree replays it (resume requires it to match the frozen prelude). A visitor
|
|
1327
|
+
with a stored theme gets it pre-paint from the FOUC script and in
|
|
1328
|
+
`useTheme()` after ThemeProvider re-syncs post-mount. Nothing to configure —
|
|
1329
|
+
but a themed component in the shell may briefly render the default theme's
|
|
1330
|
+
markup before the post-mount re-sync.
|
|
1051
1331
|
- **Shell shows CAPTURE-time data for the shell's lifetime**: a
|
|
1052
1332
|
`cache()`/`"use cache"` value baked into the shell is PINNED at capture (the
|
|
1053
1333
|
capture data snapshot) and replayed on every HIT, so the shell stays
|
|
@@ -1057,22 +1337,34 @@ evicted by tag at all — move always-fresh data into a live-lane loader (no
|
|
|
1057
1337
|
the capture read it also rides the shell, so `updateTag` on that tag drops the
|
|
1058
1338
|
shell too (next request MISSes and recaptures). An untagged entry has no such
|
|
1059
1339
|
link. If a shell region needs to be fresh, put it under a hole — a live-lane
|
|
1060
|
-
loader (no `ssr: false`) behind `loading()` or an inline `<Suspense>`, or
|
|
1061
|
-
|
|
1062
|
-
|
|
1340
|
+
loader (no `ssr: false`) behind `loading()` or an inline `<Suspense>`, or a
|
|
1341
|
+
nested promise in bake-lane loader data (holes are never pinned) — or make
|
|
1342
|
+
the SHELL itself invalidatable by tagging
|
|
1063
1343
|
it: tag the cached read, call `cacheTag(...)` from the shell-material render
|
|
1064
1344
|
code (the render-time lever), or add the tag to `ppr.tags` (operational tags
|
|
1065
1345
|
the render cannot know — a tenant id, a deploy marker). Tags are optional: if
|
|
1066
1346
|
TTL/SWR is the complete freshness policy, leave the shell untagged. Rango does not warn for that choice; with
|
|
1067
1347
|
`debugShellCapture` enabled, a stored event reports `untaggedBake: true` when
|
|
1068
1348
|
bake-lane loader material uses TTL/SWR-only invalidation.
|
|
1069
|
-
- **
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1349
|
+
- **A `"use cache"` value the shell and a live hole both read comes from the
|
|
1350
|
+
cache store in the hole**: the shell keeps the capture-time value, and a
|
|
1351
|
+
live-lane loader under `loading()` or an inline `<Suspense>` that reads the
|
|
1352
|
+
same `"use cache"` entry reads it from the store on every HIT. It is still
|
|
1353
|
+
cached under its own profile; once the entry expires or is invalidated and
|
|
1354
|
+
refreshes, the hole shows the refreshed value next to the shell's old one. The
|
|
1355
|
+
capture stores only what a HIT reads: every HIT replays the handler layer
|
|
1356
|
+
from the captured segment record, so the `"use cache"` items only handler
|
|
1357
|
+
code read are not stored. When a bake-lane loader read the same entry at
|
|
1358
|
+
capture, the shell keeps it, and the hole gets that pinned value too.
|
|
1359
|
+
- **Uncached nondeterminism in server output is frozen, not drifting**: a raw
|
|
1360
|
+
`Date.now()` / `Math.random()` / uncached `fetch` in a handler or server
|
|
1361
|
+
component renders once per capture, and the prelude and every HIT show that
|
|
1362
|
+
same value for the shell's lifetime (an uncached async server component used
|
|
1363
|
+
to render twice per capture, so the prelude and the HIT payload disagreed).
|
|
1364
|
+
If the value must change per request, move it under a hole (a live-lane
|
|
1365
|
+
loader read under `loading()` or an inline `<Suspense>`). A CLIENT component
|
|
1366
|
+
that renders such a value during SSR still mismatches on hydration, as on
|
|
1367
|
+
any SSR page.
|
|
1076
1368
|
- **Stacking with `/document-cache` or HTTP CDN caching**: both cache the
|
|
1077
1369
|
completed composite, including live-hole output, so PPR becomes redundant on
|
|
1078
1370
|
a hit. A platform CDN also bypasses every Rango middleware. Restrict this to
|