@rangojs/router 0.0.0-experimental.142 → 0.0.0-experimental.144
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/dist/vite/index.js +25 -6
- package/package.json +4 -2
- package/skills/cache-guide/SKILL.md +3 -1
- package/skills/caching/SKILL.md +41 -2
- package/skills/catalog.json +6 -0
- package/skills/composability/SKILL.md +32 -0
- package/skills/defer-hydration/SKILL.md +235 -0
- package/skills/loader/SKILL.md +5 -0
- package/skills/migrate-nextjs/SKILL.md +4 -2
- package/skills/observability/SKILL.md +8 -0
- package/skills/parallel/SKILL.md +4 -0
- package/skills/ppr/SKILL.md +110 -20
- package/skills/rango/SKILL.md +10 -0
- package/skills/route/SKILL.md +8 -0
- package/skills/typesafety/SKILL.md +1 -0
- package/skills/typesafety/generated-files-and-cli.md +30 -0
- package/skills/use-cache/SKILL.md +12 -2
- package/src/browser/partial-update.ts +7 -0
- package/src/cache/cache-key-utils.ts +29 -0
- package/src/cache/cache-scope.ts +2 -17
- package/src/cache/cache-tag.ts +60 -14
- package/src/cache/cf/cf-cache-store.ts +54 -20
- package/src/cache/document-cache.ts +17 -11
- package/src/cache/vercel/vercel-cache-store.ts +9 -19
- package/src/cloudflare/tracing.ts +7 -8
- package/src/index.rsc.ts +1 -0
- package/src/index.ts +12 -8
- package/src/redirect-origin.ts +14 -0
- package/src/route-definition/helpers-types.ts +5 -4
- package/src/route-map-builder.ts +41 -4
- package/src/router/find-match.ts +15 -1
- package/src/router/instrument.ts +9 -4
- package/src/router/lazy-includes.ts +8 -2
- package/src/router/loader-resolution.ts +14 -2
- package/src/router/match-handlers.ts +175 -133
- package/src/router/middleware.ts +40 -30
- package/src/router/router-interfaces.ts +9 -0
- package/src/router/segment-resolution/loader-snapshot.ts +98 -17
- package/src/router/telemetry-otel.ts +6 -8
- package/src/router/telemetry.ts +9 -1
- package/src/router/tracing.ts +14 -5
- package/src/router.ts +22 -14
- package/src/rsc/handler.ts +55 -32
- package/src/rsc/redirect-guard.ts +2 -1
- package/src/rsc/rsc-rendering.ts +35 -2
- package/src/rsc/shell-capture.ts +98 -20
- package/src/server/context.ts +47 -9
- package/src/server/cookie-store.ts +26 -5
- package/src/server/request-context.ts +22 -0
- package/src/ssr/index.tsx +145 -107
- package/src/testing/dispatch.ts +149 -37
- package/src/urls/path-helper-types.ts +9 -4
- package/src/vercel/tracing.ts +7 -7
- package/src/vite/inject-client-debug.ts +64 -12
- package/src/vite/router-discovery.ts +9 -1
package/dist/vite/index.js
CHANGED
|
@@ -2393,7 +2393,7 @@ import { resolve } from "node:path";
|
|
|
2393
2393
|
// package.json
|
|
2394
2394
|
var package_default = {
|
|
2395
2395
|
name: "@rangojs/router",
|
|
2396
|
-
version: "0.0.0-experimental.
|
|
2396
|
+
version: "0.0.0-experimental.144",
|
|
2397
2397
|
description: "Django-inspired RSC router with composable URL patterns",
|
|
2398
2398
|
keywords: [
|
|
2399
2399
|
"react",
|
|
@@ -2583,6 +2583,8 @@ var package_default = {
|
|
|
2583
2583
|
},
|
|
2584
2584
|
devDependencies: {
|
|
2585
2585
|
"@opentelemetry/api": "^1.9.0",
|
|
2586
|
+
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
2587
|
+
"@opentelemetry/sdk-trace-base": "^2.9.0",
|
|
2586
2588
|
"@playwright/test": "^1.49.1",
|
|
2587
2589
|
"@shared/e2e": "workspace:*",
|
|
2588
2590
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -2592,7 +2594,7 @@ var package_default = {
|
|
|
2592
2594
|
"@types/react-dom": "catalog:",
|
|
2593
2595
|
esbuild: "^0.28.1",
|
|
2594
2596
|
"happy-dom": "^20.10.1",
|
|
2595
|
-
jiti: "^2.
|
|
2597
|
+
jiti: "^2.7.0",
|
|
2596
2598
|
react: "catalog:",
|
|
2597
2599
|
"react-dom": "catalog:",
|
|
2598
2600
|
typescript: "^5.3.0",
|
|
@@ -4595,17 +4597,33 @@ import { createRequire as createRequire3, register } from "node:module";
|
|
|
4595
4597
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
4596
4598
|
|
|
4597
4599
|
// src/vite/inject-client-debug.ts
|
|
4598
|
-
function
|
|
4599
|
-
if (!id.includes("internal-debug")) return
|
|
4600
|
+
function isRouterInternalDebugId(id) {
|
|
4601
|
+
if (!id.includes("internal-debug")) return false;
|
|
4600
4602
|
const norm = id.replace(/\\/g, "/");
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
+
return /\/internal-debug\.[cm]?[jt]sx?(\?|$)/.test(norm) && (norm.includes("/@rangojs/router/") || norm.includes("/packages/rangojs-router/"));
|
|
4604
|
+
}
|
|
4605
|
+
function injectClientDebugFlag(id) {
|
|
4606
|
+
if (!isRouterInternalDebugId(id)) return null;
|
|
4603
4607
|
return {
|
|
4604
4608
|
code: `export const INTERNAL_RANGO_DEBUG = ${!!process.env.INTERNAL_RANGO_DEBUG};
|
|
4605
4609
|
`,
|
|
4606
4610
|
map: null
|
|
4607
4611
|
};
|
|
4608
4612
|
}
|
|
4613
|
+
function internalDebugNoCacheMiddleware() {
|
|
4614
|
+
return function rangoInternalDebugNoCache(req, res, next) {
|
|
4615
|
+
if (req.url && isRouterInternalDebugId(req.url)) {
|
|
4616
|
+
const setHeader = res.setHeader.bind(res);
|
|
4617
|
+
res.setHeader = (name, value) => {
|
|
4618
|
+
return setHeader(
|
|
4619
|
+
name,
|
|
4620
|
+
name.toLowerCase() === "cache-control" ? "no-cache" : value
|
|
4621
|
+
);
|
|
4622
|
+
};
|
|
4623
|
+
}
|
|
4624
|
+
next();
|
|
4625
|
+
};
|
|
4626
|
+
}
|
|
4609
4627
|
|
|
4610
4628
|
// src/vite/plugins/virtual-stub-plugin.ts
|
|
4611
4629
|
function createVirtualStubPlugin() {
|
|
@@ -6841,6 +6859,7 @@ function createRouterDiscoveryPlugin(entryPath, opts) {
|
|
|
6841
6859
|
if (s.isBuildMode) return;
|
|
6842
6860
|
if (globalThis.__rscRouterDiscoveryActive) return;
|
|
6843
6861
|
s.devServer = server;
|
|
6862
|
+
server.middlewares.use(internalDebugNoCacheMiddleware());
|
|
6844
6863
|
let resolveDiscovery;
|
|
6845
6864
|
const discoveryPromise = new Promise((resolve12) => {
|
|
6846
6865
|
resolveDiscovery = resolve12;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rangojs/router",
|
|
3
|
-
"version": "0.0.0-experimental.
|
|
3
|
+
"version": "0.0.0-experimental.144",
|
|
4
4
|
"description": "Django-inspired RSC router with composable URL patterns",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -190,6 +190,8 @@
|
|
|
190
190
|
},
|
|
191
191
|
"devDependencies": {
|
|
192
192
|
"@opentelemetry/api": "^1.9.0",
|
|
193
|
+
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
194
|
+
"@opentelemetry/sdk-trace-base": "^2.9.0",
|
|
193
195
|
"@playwright/test": "^1.49.1",
|
|
194
196
|
"@shared/e2e": "workspace:*",
|
|
195
197
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -199,7 +201,7 @@
|
|
|
199
201
|
"@types/react-dom": "catalog:",
|
|
200
202
|
"esbuild": "^0.28.1",
|
|
201
203
|
"happy-dom": "^20.10.1",
|
|
202
|
-
"jiti": "^2.
|
|
204
|
+
"jiti": "^2.7.0",
|
|
203
205
|
"react": "catalog:",
|
|
204
206
|
"react-dom": "catalog:",
|
|
205
207
|
"typescript": "^5.3.0",
|
|
@@ -20,7 +20,9 @@ caching:
|
|
|
20
20
|
1. **Stored-value freshness** — _is a cached value still good?_
|
|
21
21
|
→ `"use cache"` (fn/component), `cache()` (segment), loader `cache()` (loader data).
|
|
22
22
|
Entries expire by **TTL/SWR** and can be tagged (`cache({ tags })` or runtime
|
|
23
|
-
`cacheTag(...tags)`
|
|
23
|
+
`cacheTag(...tags)` — inside `"use cache"` it tags that entry; called during a
|
|
24
|
+
request render outside `"use cache"` it tags the document/shell artifact).
|
|
25
|
+
Built-in stores (`MemorySegmentCacheStore`, `CFCacheStore`)
|
|
24
26
|
index by tag; invalidate on demand with `updateTag(...tags)` (awaitable,
|
|
25
27
|
read-your-own-writes) or `revalidateTag(...tags)` (background, non-blocking).
|
|
26
28
|
Both hard-purge; the difference is awaitability, not stale-serving.
|
package/skills/caching/SKILL.md
CHANGED
|
@@ -91,9 +91,27 @@ cache(
|
|
|
91
91
|
);
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
## When cache() does not pay
|
|
95
|
+
|
|
96
|
+
A cache hit is not free: it still runs middleware, the store read, and the
|
|
97
|
+
document render AROUND the cached segment. The win is proportional to what
|
|
98
|
+
the cached render itself costs — measured on a deployed Cloudflare worker
|
|
99
|
+
(2026-07), a trivial page inside `cache()` served hits at p50 36 ms while
|
|
100
|
+
misses (render + store) served at 35 ms: indistinguishable. The same
|
|
101
|
+
boundary around an expensive render (slow data, big trees) is where the TTL
|
|
102
|
+
pays for itself.
|
|
103
|
+
|
|
104
|
+
Rule of thumb: reach for `cache()` when the segment's own render cost is
|
|
105
|
+
meaningfully above your latency floor — expensive render-embedded data work,
|
|
106
|
+
large component trees, third-party calls captured in the render. Do not wrap cheap
|
|
107
|
+
pages "just in case": you add store traffic and invalidation surface for no
|
|
108
|
+
latency win. If the data is what's expensive and it changes per-request,
|
|
109
|
+
prefer a loader with `cache()` on the loader DATA (see "Loader-Level
|
|
110
|
+
Caching") over caching the rendered segment.
|
|
111
|
+
|
|
94
112
|
## Tag-Based Invalidation
|
|
95
113
|
|
|
96
|
-
Tag cached entries, then invalidate them on demand. Tags can be attached
|
|
114
|
+
Tag cached entries, then invalidate them on demand. Tags can be attached four ways:
|
|
97
115
|
|
|
98
116
|
```typescript
|
|
99
117
|
// 1. Static tags in the cache() DSL
|
|
@@ -111,8 +129,22 @@ async function getProduct(id: string) {
|
|
|
111
129
|
cacheTag(`product:${id}`, "products"); // variadic, additive
|
|
112
130
|
return db.getProduct(id);
|
|
113
131
|
}
|
|
132
|
+
|
|
133
|
+
// 4. Render-callable — a plain server component (no "use cache" in its tree)
|
|
134
|
+
// records onto the request's document/shell artifact.
|
|
135
|
+
function CampaignBanner() {
|
|
136
|
+
cacheTag("campaign:spring"); // rides ctx._requestTags → shell/document entry
|
|
137
|
+
return <aside>Spring sale</aside>;
|
|
138
|
+
}
|
|
114
139
|
```
|
|
115
140
|
|
|
141
|
+
Form 4 is how you make a PPR shell or a `/document-cache` page tag-invalidatable
|
|
142
|
+
without wrapping anything in `"use cache"`: the tag rides the request's
|
|
143
|
+
`_requestTags` onto the shell/document entry, and `revalidateTag` then evicts it.
|
|
144
|
+
On a route that is neither PPR nor document-cached the tag records where nothing
|
|
145
|
+
reads it — a silent no-op, so don't expect a bare `cacheTag()` to tag an ordinary
|
|
146
|
+
uncached page.
|
|
147
|
+
|
|
116
148
|
Invalidate with one of two server-only verbs (both variadic, imported from
|
|
117
149
|
`@rangojs/router`):
|
|
118
150
|
|
|
@@ -153,7 +185,8 @@ converge within `tagCacheTtl` (the **maximum extra cross-colo invalidation
|
|
|
153
185
|
latency** when no purge is wired). Keep it small (e.g. 30–60), or wire a purge
|
|
154
186
|
(below) and set it large. (Contrast `tagInvalidationTtl`, which must be _large_
|
|
155
187
|
— it bounds how long the KV marker itself lives and must exceed your max entry
|
|
156
|
-
TTL+SWR.
|
|
188
|
+
TTL+SWR. Left unset there is no expiry: KV markers accumulate unbounded under
|
|
189
|
+
high-cardinality tags, so set it above your largest entry TTL+SWR to bound them.)
|
|
157
190
|
|
|
158
191
|
To make other colos prompt without a short `tagCacheTtl`, pass `onRevalidateTag`:
|
|
159
192
|
each cached marker carries a namespaced Cloudflare `Cache-Tag`, and the hook is
|
|
@@ -417,6 +450,12 @@ is **not** guarded. `ctx.use()` is a server-side escape hatch for non-rendered
|
|
|
417
450
|
uses (set a ctx var, make a routing decision); never render its result inside a
|
|
418
451
|
cached handler.
|
|
419
452
|
|
|
453
|
+
This is the **consumption-lane rule**, and it holds identically for every
|
|
454
|
+
shared artifact — `cache()`, `"use cache"`, and the PPR shell (`/ppr`):
|
|
455
|
+
handler consumption = baked copy with identity reads permitted; client-side
|
|
456
|
+
`useLoader` = live. Stated once in `/rango` → Invariants; pinned by
|
|
457
|
+
semantic-matrix row PPR3 and the `e2e/cache.test.ts` "baked copy" case.
|
|
458
|
+
|
|
420
459
|
```typescript
|
|
421
460
|
// WRONG — throws: cookies() read directly in a cached handler
|
|
422
461
|
cache({ ttl: 60 }, () => [
|
package/skills/catalog.json
CHANGED
|
@@ -57,6 +57,12 @@
|
|
|
57
57
|
"argumentHint": "",
|
|
58
58
|
"path": "skills/debug-manifest/SKILL.md"
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
"name": "defer-hydration",
|
|
62
|
+
"description": "Keep the full body HTML in a PPR shell's first paint while moving a heavy subtree's hydration off the initial main-thread task — a gated Suspense boundary with the content as its own fallback, released on first idle. Use when a shell HIT paints fast but one long hydration task blocks the main thread, TTI/INP is poor despite instant paint, or a plain Suspense boundary left an empty hole in the frozen prelude.",
|
|
63
|
+
"argumentHint": "",
|
|
64
|
+
"path": "skills/defer-hydration/SKILL.md"
|
|
65
|
+
},
|
|
60
66
|
{
|
|
61
67
|
"name": "document-cache",
|
|
62
68
|
"description": "Cache the whole HTTP response at the edge with Cache-Control headers. Use when caching an entire page or response at a CDN edge, setting Cache-Control headers, or cutting origin hits for public pages — not for caching a single segment or function.",
|
|
@@ -210,6 +210,38 @@ in the group — including nested `include()`s inside the split module. Only the
|
|
|
210
210
|
module's runtime evaluation defers. `rango generate` resolves the `() => import()`
|
|
211
211
|
the same way, so a code-split group is still fully typed.
|
|
212
212
|
|
|
213
|
+
### Sizing async include groups (measured)
|
|
214
|
+
|
|
215
|
+
The first request into an async group pays that group's chunk import; every
|
|
216
|
+
request after that is flat. Measured on a deployed Cloudflare worker with
|
|
217
|
+
26k routes (2026-07, warm RTT floor ~23 ms):
|
|
218
|
+
|
|
219
|
+
| Group size | First-hit latency |
|
|
220
|
+
| -------------------------- | ------------------------------------ |
|
|
221
|
+
| ~240 routes | ~75 ms (≈ RTT + eval) |
|
|
222
|
+
| ~5,000 routes | ~137 ms |
|
|
223
|
+
| ~9,000 routes | ~188 ms |
|
|
224
|
+
| 3-level nested async chain | ~464 ms (levels import sequentially) |
|
|
225
|
+
|
|
226
|
+
Three rules fall out of those numbers:
|
|
227
|
+
|
|
228
|
+
1. **Prefer more, smaller groups over few giant ones.** First-hit cost scales
|
|
229
|
+
with routes-per-chunk; fifty 250-route groups each cost a fraction of one
|
|
230
|
+
9k-route group, and only the group actually visited pays anything.
|
|
231
|
+
2. **Keep async-include chains shallow on latency-sensitive paths.** Each
|
|
232
|
+
nested `() => import()` level awaits in sequence, so depth multiplies the
|
|
233
|
+
first hit. Nesting eager includes inside one async module costs one chunk;
|
|
234
|
+
nesting async inside async costs one chunk per level.
|
|
235
|
+
3. **Give sibling groups distinct static prefixes.** Siblings that share a
|
|
236
|
+
static prefix (`include("/x/:a", …)` next to `include("/x/:b", …)`) all
|
|
237
|
+
import on the first hit to that prefix — the router cannot tell which one
|
|
238
|
+
matches before loading them.
|
|
239
|
+
|
|
240
|
+
Warm-path matching is O(path segments) via the precomputed trie regardless of
|
|
241
|
+
group layout — this sizing only shapes cold/first-hit behavior. For
|
|
242
|
+
latency-critical prefixes, a post-deploy warmup ping (one request per prefix)
|
|
243
|
+
erases first-hit cost for the isolate entirely.
|
|
244
|
+
|
|
213
245
|
## Composition Types
|
|
214
246
|
|
|
215
247
|
For typed factories, import the composition types:
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: defer-hydration
|
|
3
|
+
description: Keep the full body HTML in a PPR shell's first paint while moving a heavy subtree's hydration off the initial main-thread task — a gated Suspense boundary with the content as its own fallback, released on first idle. Use when a shell HIT paints fast but one long hydration task blocks the main thread, TTI/INP is poor despite instant paint, or a plain Suspense boundary left an empty hole in the frozen prelude.
|
|
4
|
+
argument-hint:
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Deferred hydration: gated boundary, content-as-fallback
|
|
8
|
+
|
|
9
|
+
PPR (`/ppr`) makes first paint instant — the frozen prelude flushes before any
|
|
10
|
+
render work. It does nothing about what happens next: React hydrates the page
|
|
11
|
+
as one synchronous main-thread task, and on a content-heavy page that task can
|
|
12
|
+
block every click and scroll handler for seconds. Measured on a production
|
|
13
|
+
storefront homepage (shell HIT, production build, M-series laptop): a single
|
|
14
|
+
2543ms task. On the dev server the same page produced a 7.2s task — the page
|
|
15
|
+
was dead for ~11s. Fast paint, frozen page.
|
|
16
|
+
|
|
17
|
+
The obvious fix — wrap the heavy subtree in `<Suspense>` so it hydrates later —
|
|
18
|
+
trades the paint away: under shell capture that boundary postpones, and the
|
|
19
|
+
frozen prelude ships an empty `<main>`. This recipe gets both: the full body
|
|
20
|
+
HTML in the prelude AND its hydration off the initial task, released on first
|
|
21
|
+
idle at retry-lane priority.
|
|
22
|
+
|
|
23
|
+
| | baseline | plain `fallback={null}` boundary | gated content-as-fallback |
|
|
24
|
+
| -------------------------------- | -------- | -------------------------------- | ------------------------- |
|
|
25
|
+
| body in first paint | yes | **no — empty `<main>`** | yes |
|
|
26
|
+
| worst main-thread task | 2543ms | 844ms | **386ms** |
|
|
27
|
+
| total blocked time (>50ms tasks) | 2705ms | 1436ms | **554ms** |
|
|
28
|
+
| interactive (menu click works) | ~3.5s | ~1.6s | ~1.6s |
|
|
29
|
+
|
|
30
|
+
Measure your own page before and after — the win depends on how much of the
|
|
31
|
+
hydration cost lives under the boundary (see "Verifying and measuring").
|
|
32
|
+
|
|
33
|
+
## The recipe
|
|
34
|
+
|
|
35
|
+
~40 lines, plain React, no rango imports — copy it into your app:
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
"use client";
|
|
39
|
+
import type { ReactNode } from "react";
|
|
40
|
+
import { Suspense, startTransition, use, useEffect } from "react";
|
|
41
|
+
|
|
42
|
+
let released = false;
|
|
43
|
+
let releaseFn: (() => void) | undefined;
|
|
44
|
+
const gate = new Promise<void>((resolve) => {
|
|
45
|
+
releaseFn = resolve;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function releaseHydrationGate() {
|
|
49
|
+
if (released) return;
|
|
50
|
+
released = true;
|
|
51
|
+
// Transition so the boundary retry/hydration is scheduled non-urgent,
|
|
52
|
+
// never as a sync flush from the idle callback.
|
|
53
|
+
startTransition(() => releaseFn?.());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function HydrationGate() {
|
|
57
|
+
// Server: inert (children SSR normally). Client before release: suspend,
|
|
58
|
+
// so React skips hydrating the boundary and KEEPS the server DOM.
|
|
59
|
+
if (typeof window !== "undefined" && !released) use(gate);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ReleaseHydrationGate() {
|
|
64
|
+
// Sibling of the boundary — NEVER under it (its effect would deadlock
|
|
65
|
+
// holding its own key). Hydrates with the early pass.
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (released) return;
|
|
68
|
+
if ("requestIdleCallback" in window) {
|
|
69
|
+
requestIdleCallback(releaseHydrationGate, { timeout: 1500 });
|
|
70
|
+
} else {
|
|
71
|
+
setTimeout(releaseHydrationGate, 200);
|
|
72
|
+
}
|
|
73
|
+
}, []);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function DeferredHydration({ children }: { children: ReactNode }) {
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<ReleaseHydrationGate />
|
|
81
|
+
<Suspense fallback={children}>
|
|
82
|
+
<HydrationGate />
|
|
83
|
+
{children}
|
|
84
|
+
</Suspense>
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Wrap the heavy subtree — typically the page body under the app chrome:
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
<DeferredHydration>
|
|
94
|
+
<HomePageBody />
|
|
95
|
+
</DeferredHydration>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The chrome (header, nav — whatever must respond to the first click) stays
|
|
99
|
+
outside the boundary and hydrates in the early, now-small task. Everything
|
|
100
|
+
inside hydrates after first idle.
|
|
101
|
+
|
|
102
|
+
## Why `fallback={children}` is load-bearing
|
|
103
|
+
|
|
104
|
+
This is not a style choice; it is the half of the recipe that makes it
|
|
105
|
+
PPR-compatible.
|
|
106
|
+
|
|
107
|
+
Shell capture aborts on flight byte-quiet (`src/rsc/shell-capture.ts`,
|
|
108
|
+
`FLIGHT_QUIET_HOPS`): once the Flight source has been byte-silent for the
|
|
109
|
+
quiet window, the fizz render freezes. A big HTML subtree under _any_
|
|
110
|
+
`<Suspense>` boundary cannot finish inside that window, so the boundary always
|
|
111
|
+
postpones — boundary placement cannot fix it. Verified both ways: wrapping the
|
|
112
|
+
client island from outside AND placing the boundary inside the island both
|
|
113
|
+
baked `<!--$?--><template id="B:…">` into `<main>`, i.e. an empty body in the
|
|
114
|
+
frozen prelude.
|
|
115
|
+
|
|
116
|
+
With the content as the fallback, the unavoidable postpone _becomes the
|
|
117
|
+
delivery mechanism_: the shell bakes the fallback, and the fallback IS the
|
|
118
|
+
body. In `/ppr` hole-doctrine terms, this is the PHYSICS class exploited
|
|
119
|
+
deliberately — you cannot stop the boundary from becoming a hole, so you make
|
|
120
|
+
the hole's baked fallback carry the real markup.
|
|
121
|
+
|
|
122
|
+
## Why the client gate is free
|
|
123
|
+
|
|
124
|
+
Suspending during hydration keeps the **server DOM**, not the fallback. When
|
|
125
|
+
`HydrationGate` suspends on the client, React skips hydrating that boundary
|
|
126
|
+
and leaves the baked HTML in place — visible, styled, inert. On release, the
|
|
127
|
+
boundary retries on the retry lane (interruptible, non-urgent thanks to the
|
|
128
|
+
`startTransition` in `releaseHydrationGate`), and the existing DOM hydrates in
|
|
129
|
+
place. No blank, no flicker, no re-paint.
|
|
130
|
+
|
|
131
|
+
## The sync-update trap (scar tissue)
|
|
132
|
+
|
|
133
|
+
A **synchronous** update that reaches into a dehydrated boundary makes React
|
|
134
|
+
abandon hydration and client-render it instead. That client render suspends on
|
|
135
|
+
the gate and renders the fallback. With `fallback={children}` this is a visual
|
|
136
|
+
no-op (but wasted work); with `fallback={null}` it blanks the page.
|
|
137
|
+
|
|
138
|
+
The corollary: provider data syncs that land right after the chrome hydrates —
|
|
139
|
+
basket, wishlist, auth state read from storage in an effect — MUST be
|
|
140
|
+
`startTransition`-wrapped. This was measured, not theorized: without the
|
|
141
|
+
transitions, the boundary was force-hydrated synchronously and the split
|
|
142
|
+
evaporated (the 2543ms task survived intact).
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
const stored = readBasketFromStorage();
|
|
147
|
+
startTransition(() => setBasket(stored)); // NOT a bare setBasket(stored)
|
|
148
|
+
}, []);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Pre-release interaction semantics
|
|
152
|
+
|
|
153
|
+
Between paint and release (window ≈ one idle, capped by the `requestIdleCallback`
|
|
154
|
+
timeout — 1500ms in the reference):
|
|
155
|
+
|
|
156
|
+
- **Native anchors work** — they are plain HTML in the server DOM, plus any
|
|
157
|
+
click-delegation living above the boundary.
|
|
158
|
+
- **React `onClick`s inside the gated subtree queue** via React's event replay
|
|
159
|
+
and fire on hydration after release.
|
|
160
|
+
|
|
161
|
+
If the gated subtree's first-click latency matters more than idle timing,
|
|
162
|
+
release on interaction instead (see Variations).
|
|
163
|
+
|
|
164
|
+
## Known cost: the body rides twice (measure it, don't guess)
|
|
165
|
+
|
|
166
|
+
On a shell HIT the gated subtree's HTML is in the response twice — once as the
|
|
167
|
+
baked fallback in the prelude, once as the resumed hole content (the resume
|
|
168
|
+
re-renders and re-ships it; there is no bake-through). Homepage measurement:
|
|
169
|
+
234KB → 302KB gzipped (+68KB, +29%; raw +1.05MB). It is post-paint bandwidth,
|
|
170
|
+
not render-blocking — the visible prelude streams first — but it is real bytes
|
|
171
|
+
on every document GET. Weigh it per page; on a small body the recipe may not
|
|
172
|
+
pay for itself.
|
|
173
|
+
|
|
174
|
+
## Verifying and measuring
|
|
175
|
+
|
|
176
|
+
Production build only — dev-server hydration numbers are noise (module
|
|
177
|
+
transforms dominate; the 7.2s dev task above vs 2543ms in production).
|
|
178
|
+
|
|
179
|
+
**Body in the prelude.** Fetch the document and check a distinctive piece of
|
|
180
|
+
body markup appears BEFORE the first resumed segment:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
curl -s -H "Accept: text/html" http://localhost:4173/ \
|
|
184
|
+
| awk '{ if (match($0, /<div hidden id="S:/)) { print substr($0, 1, RSTART); exit } print }' \
|
|
185
|
+
| grep -c "Best Sellers" # any string unique to the gated body
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`0` with `<!--$?--><template id="B:` markers inside `<main>` means an empty
|
|
189
|
+
hole baked instead — the fallback is not the content (wrong boundary, or a
|
|
190
|
+
plain `fallback={null}`/skeleton boundary).
|
|
191
|
+
|
|
192
|
+
**Main-thread tasks.** Paste a longtask observer in the console before
|
|
193
|
+
reloading, then compare the worst task with the recipe on and off:
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
new PerformanceObserver((l) =>
|
|
197
|
+
l
|
|
198
|
+
.getEntries()
|
|
199
|
+
.forEach((e) => console.log("longtask", Math.round(e.duration))),
|
|
200
|
+
).observe({ entryTypes: ["longtask"] });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Interactivity.** Click the chrome (menu, nav) immediately after paint — it
|
|
204
|
+
should respond while the gated body is still inert.
|
|
205
|
+
|
|
206
|
+
## Variations
|
|
207
|
+
|
|
208
|
+
- **Release on visible** — an `IntersectionObserver` per boundary instead of
|
|
209
|
+
`requestIdleCallback`: below-the-fold sections hydrate only when scrolled
|
|
210
|
+
near.
|
|
211
|
+
- **Release on first interaction** — a capture-phase listener
|
|
212
|
+
(`pointerdown`/`keydown` on `window`) that releases immediately: the queued
|
|
213
|
+
event replays into the touched boundary and React's selective hydration
|
|
214
|
+
prioritizes it. Best when the gated subtree is itself the interaction
|
|
215
|
+
target.
|
|
216
|
+
- **One shared gate vs per-boundary gates** — the reference uses one
|
|
217
|
+
module-level gate (first release wins, all boundaries hydrate together).
|
|
218
|
+
Multiple independent boundaries (visible-based, per-section) need one
|
|
219
|
+
gate/`released` pair per boundary — factor the module into a
|
|
220
|
+
`createHydrationGate()` if you go there.
|
|
221
|
+
|
|
222
|
+
## What this deliberately is not
|
|
223
|
+
|
|
224
|
+
The duplicated payload has an obvious framework-level fix: a "bake-through"
|
|
225
|
+
boundary that bakes the boundary _content_ into the prelude and skips the
|
|
226
|
+
redundant hole resume. That is deliberately NOT part of this recipe — a recipe
|
|
227
|
+
has zero API commitment, and React's `<Activity>`/postpone work may land under
|
|
228
|
+
this exact space. The recipe survives that future; a primitive might not.
|
|
229
|
+
|
|
230
|
+
## Related
|
|
231
|
+
|
|
232
|
+
- `/ppr` — the shell/hole mechanics this recipe rides on (hole doctrine:
|
|
233
|
+
PHYSICS class), and why the capture postpones any big Suspense subtree
|
|
234
|
+
- `src/rsc/shell-capture.ts` — the byte-quiet capture window
|
|
235
|
+
(`FLIGHT_QUIET_HOPS`) that makes `fallback={children}` mandatory
|
package/skills/loader/SKILL.md
CHANGED
|
@@ -147,6 +147,11 @@ same memoized result — loaders never run twice per request.
|
|
|
147
147
|
- The handler output depends on the loader data. If the route is inside
|
|
148
148
|
`cache()`, the handler is cached with the loader result baked in —
|
|
149
149
|
defeating the live data guarantee.
|
|
150
|
+
- The same holds under a PPR shell capture (`/ppr`): handler consumption is
|
|
151
|
+
the BAKED lane — the loader executes at capture (identity reads permitted)
|
|
152
|
+
and the rendered value is a capture-time copy; `useLoader` client-side is
|
|
153
|
+
the live lane. One rule across `cache()`, `"use cache"`, and PPR: the
|
|
154
|
+
consumption-lane rule (`/rango` → Invariants).
|
|
150
155
|
- Non-cacheable variable reads (`createVar({ cache: false })`) inside the
|
|
151
156
|
handler still throw, even if the data came from a loader.
|
|
152
157
|
- Prefer DSL `loader()` + client `useLoader()` for data that depends on
|
|
@@ -447,8 +447,10 @@ Next.js conflates two things under "revalidation." Rango separates them — and
|
|
|
447
447
|
tag-based cache invalidation now maps directly.
|
|
448
448
|
|
|
449
449
|
**1. Cache invalidation (bust cached values) — direct equivalent.** Tag entries
|
|
450
|
-
with `cache({ tags })` or
|
|
451
|
-
`
|
|
450
|
+
with `cache({ tags })` or runtime `cacheTag(...tags)`. `cacheTag()` works inside a
|
|
451
|
+
`"use cache"` function (tags that entry) AND render-callable in a plain server
|
|
452
|
+
component (no `"use cache"` needed — it tags the document / PPR shell the component
|
|
453
|
+
renders into). Then invalidate by tag:
|
|
452
454
|
|
|
453
455
|
```typescript
|
|
454
456
|
// Next.js Rango
|
|
@@ -58,6 +58,14 @@ Read the timeline as intervals:
|
|
|
58
58
|
- Cache, route matching, middleware pre/post, RSC serialization, and SSR phases
|
|
59
59
|
appear as separate spans, so the slow phase is visible without guessing.
|
|
60
60
|
|
|
61
|
+
**Deployed Cloudflare caveat**: on production Workers, timers are frozen
|
|
62
|
+
during request execution (Spectre mitigation), so `Server-Timing` durations
|
|
63
|
+
read as ~0 on the deployed edge — they only advance across genuine awaited
|
|
64
|
+
I/O. The waterfall is a LOCAL diagnostic (dev, `vite preview`,
|
|
65
|
+
`wrangler dev`); for deployed workers, measure from the client
|
|
66
|
+
(`PerformanceResourceTiming`, TTFB) and use structured telemetry below for
|
|
67
|
+
server-side events.
|
|
68
|
+
|
|
61
69
|
## Structured telemetry
|
|
62
70
|
|
|
63
71
|
Use telemetry when you want durable production events rather than a one-request
|
package/skills/parallel/SKILL.md
CHANGED
|
@@ -239,6 +239,8 @@ layout(<AccountLayout />, () => [
|
|
|
239
239
|
|
|
240
240
|
A slot's `loading()` (whether from `handler.use` or explicit) makes that slot an independent streaming unit, exactly as in the **Streaming Behavior** section above.
|
|
241
241
|
|
|
242
|
+
Under a shared artifact (`cache()`, `"use cache"`, a PPR shell), the server-side `await ctx.use(CartLoader)` above is the BAKED lane — the capture-time value (identity reads included) freezes into the artifact; consume the loader client-side (`useLoader` in a `"use client"` component) to keep the slot live per request. One rule, stated once: `/rango` → Invariants ("the consumption-lane rule").
|
|
243
|
+
|
|
242
244
|
The `parallel` mount site has the narrowest allow-list for `handler.use` items — slots cannot bring their own middleware or layout, only `revalidate`, `loader`, `loading`, `errorBoundary`, `notFoundBoundary`, and `transition`. See [skills/handler-use](../handler-use/SKILL.md) for the full table and merge rules.
|
|
243
245
|
|
|
244
246
|
`transition` is allowed in the slot allow-list, but slot-level rendering does **not** currently apply a `<ViewTransition>` wrapper — only the layout/route wraps take effect at render time. For a modal-only morph today, use an element-level React `<ViewTransition>` inside the slot's component. The reverse direction is the useful guarantee: a layout-level `transition()` fires when the layout's default outlet content changes but **not** when a `<ParallelOutlet />` mounts new content (modal opens are not subtree updates of the layout VT). See [skills/view-transitions](../view-transitions/SKILL.md) for the wrap rules and the intercept caveat.
|
|
@@ -271,6 +273,8 @@ parallel(
|
|
|
271
273
|
|
|
272
274
|
Per-slot merge order is **handler.use → shared use → slot-local use**. Slot-local is the narrowest scope, so it wins for last-write-wins items. See [skills/handler-use § `loading()` is a single-assignment item — scope it correctly](../handler-use/SKILL.md#loading-is-a-single-assignment-item--scope-it-correctly) for the full reasoning.
|
|
273
275
|
|
|
276
|
+
Typing note: a BARE arrow slot handler infers its ctx (`"@cart": (ctx) => ...`), but an arrow inside a DESCRIPTOR needs an explicit annotation — `handler: (ctx: HandlerContext) => ...` — because `StaticHandlerDefinition` in the slot union contributes a second callable to the contextual type and TS declines to pick a signature.
|
|
277
|
+
|
|
274
278
|
## Slot Override Semantics
|
|
275
279
|
|
|
276
280
|
When multiple `parallel()` calls define the same slot name, **the last
|