@timber-js/app 0.2.0-alpha.241 → 0.2.0-alpha.242
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/_chunks/{actions-BCYVyoFl.js → actions-BkwgRwCl.js} +37 -9
- package/dist/_chunks/actions-BkwgRwCl.js.map +1 -0
- package/dist/_chunks/{als-registry-fabsRnPY.js → als-registry-C-iwbtvI.js} +1 -2
- package/dist/_chunks/{als-registry-fabsRnPY.js.map → als-registry-C-iwbtvI.js.map} +1 -1
- package/dist/_chunks/{cache-api-n5FL4wFs.js → cache-api-BGA7c5qJ.js} +5 -5
- package/dist/_chunks/{cache-api-n5FL4wFs.js.map → cache-api-BGA7c5qJ.js.map} +1 -1
- package/dist/_chunks/{chains-IswOWMnq.js → chains-Cuwwjv6T.js} +2 -2
- package/dist/_chunks/{chains-IswOWMnq.js.map → chains-Cuwwjv6T.js.map} +1 -1
- package/dist/_chunks/chains-LGjBHfSN.js +1 -0
- package/dist/_chunks/{classify-B08RCF6s.js → classify-Y8S9C0Na.js} +2 -2
- package/dist/_chunks/{classify-B08RCF6s.js.map → classify-Y8S9C0Na.js.map} +1 -1
- package/dist/_chunks/{cli-check-tpFb6pBU.js → cli-check-KeE1QaIx.js} +3 -3
- package/dist/_chunks/{cli-check-tpFb6pBU.js.map → cli-check-KeE1QaIx.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-DRNJutey.js → cli-schema-sync-DZEF31wd.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-DRNJutey.js.map → cli-schema-sync-DZEF31wd.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-C0pXBtzG.js → cli-schema-sync-_y5O6MIg.js} +1 -1
- package/dist/_chunks/{client-dep-entries-Dw5Dvatr.js → client-dep-entries-DpiwvoDi.js} +2 -2
- package/dist/_chunks/{client-dep-entries-Dw5Dvatr.js.map → client-dep-entries-DpiwvoDi.js.map} +1 -1
- package/dist/_chunks/{convention-lint-BfC_dAhZ.js → convention-lint-0AEsPK2T.js} +19 -5
- package/dist/_chunks/convention-lint-0AEsPK2T.js.map +1 -0
- package/dist/_chunks/dev-server-CboXr8zX.js +1 -0
- package/dist/_chunks/{dev-server-3R6Bl9_R.js → dev-server-DYDr8KIc.js} +2 -3
- package/dist/_chunks/dev-server-DYDr8KIc.js.map +1 -0
- package/dist/_chunks/{error-boundary-Dfhxigko.js → error-boundary-wuNvAJ4n.js} +8 -15
- package/dist/_chunks/error-boundary-wuNvAJ4n.js.map +1 -0
- package/dist/_chunks/{flight-source-node-QOpWZATb.js → flight-source-node-KQsX_OhS.js} +4 -7
- package/dist/_chunks/flight-source-node-KQsX_OhS.js.map +1 -0
- package/dist/_chunks/{json-lossy-check-5KFcC1yt.js → json-lossy-check-BVDALqMf.js} +2 -2
- package/dist/_chunks/{json-lossy-check-5KFcC1yt.js.map → json-lossy-check-BVDALqMf.js.map} +1 -1
- package/dist/_chunks/key-headers-uIig1_mU.js +40 -0
- package/dist/_chunks/key-headers-uIig1_mU.js.map +1 -0
- package/dist/_chunks/{live-graph-D1dfVqoT.js → live-graph-VhzO7Ol9.js} +4 -4
- package/dist/_chunks/{live-graph-D1dfVqoT.js.map → live-graph-VhzO7Ol9.js.map} +1 -1
- package/dist/_chunks/{logger-BvGxPd1e.js → logger-C4m8rfMy.js} +2 -2
- package/dist/_chunks/{logger-BvGxPd1e.js.map → logger-C4m8rfMy.js.map} +1 -1
- package/dist/_chunks/metadata-routes-MXNjWOt5.js.map +1 -1
- package/dist/_chunks/{node-response-D5cfiyWP.js → node-response-8Vz29cGS.js} +2 -2
- package/dist/_chunks/{node-response-D5cfiyWP.js.map → node-response-8Vz29cGS.js.map} +1 -1
- package/dist/_chunks/{poison-scan-CX02ilxN.js → poison-scan-Dpl3ibG-.js} +2 -2
- package/dist/_chunks/{poison-scan-CX02ilxN.js.map → poison-scan-Dpl3ibG-.js.map} +1 -1
- package/dist/_chunks/{scanner-DneYxQoY.js → scanner-CCEHN9Jg.js} +2 -2
- package/dist/_chunks/{scanner-DneYxQoY.js.map → scanner-CCEHN9Jg.js.map} +1 -1
- package/dist/_chunks/{sizeof-BtQ3ErLf.js → sizeof-CIF7fwSJ.js} +2 -2
- package/dist/_chunks/{sizeof-BtQ3ErLf.js.map → sizeof-CIF7fwSJ.js.map} +1 -1
- package/dist/_chunks/{walkers-C9R2A4jN.js → walkers-BbotBhNG.js} +3 -3
- package/dist/_chunks/{walkers-C9R2A4jN.js.map → walkers-BbotBhNG.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cdn/workers-cache-purge.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/browser-entry/router-init.d.ts +0 -1
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +3 -5
- package/dist/client/internal.js.map +1 -1
- package/dist/client/navigation-commit.d.ts +0 -7
- package/dist/client/navigation-commit.d.ts.map +1 -1
- package/dist/client/outlet-content-cache.d.ts +16 -42
- package/dist/client/outlet-content-cache.d.ts.map +1 -1
- package/dist/client/outlet-scope-context.d.ts +4 -4
- package/dist/client/outlet-scope-context.d.ts.map +1 -1
- package/dist/client/params-context.d.ts +1 -1
- package/dist/client/router-types.d.ts +3 -13
- package/dist/client/router-types.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/segment-cache.d.ts +2 -2
- package/dist/client/segment-outlet.d.ts +12 -15
- package/dist/client/segment-outlet.d.ts.map +1 -1
- package/dist/client/stale-segment.d.ts +2 -2
- package/dist/config-types.d.ts +0 -17
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/native/rsc/manifest.json +2 -4
- package/dist/native/rsc/routing/segment-keys.js.map +1 -1
- package/dist/native/rsc/server/als-registry.js +1 -2
- package/dist/native/rsc/server/als-registry.js.map +1 -1
- package/dist/native/rsc/server/client-state-tree.js +1 -5
- package/dist/native/rsc/server/client-state-tree.js.map +1 -1
- package/dist/native/rsc/server/flight-source-node.js +2 -5
- package/dist/native/rsc/server/flight-source-node.js.map +1 -1
- package/dist/native/rsc/server/flight-source.js +6 -41
- package/dist/native/rsc/server/flight-source.js.map +1 -1
- package/dist/native/rsc/server/framework-stack-frames.js.map +1 -1
- package/dist/native/rsc/server/request-context.js +3 -3
- package/dist/native/rsc/server/request-context.js.map +1 -1
- package/dist/native/rsc/server/route-element-builder.js +5 -5
- package/dist/native/rsc/server/route-element-builder.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +4 -30
- package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +0 -2
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/rsc-stream.js +2 -5
- package/dist/native/rsc/server/rsc-entry/rsc-stream.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/outlet-gate.js +44 -0
- package/dist/native/rsc/server/segment-lifetime/outlet-gate.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/read-rule.js +25 -3
- package/dist/native/rsc/server/segment-lifetime/read-rule.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/read-scope.js +3 -2
- package/dist/native/rsc/server/segment-lifetime/read-scope.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/segment-key.js +17 -3
- package/dist/native/rsc/server/segment-lifetime/segment-key.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js +4 -4
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js.map +1 -1
- package/dist/native/rsc/server/slot-resolver.js +3 -3
- package/dist/native/rsc/server/slot-resolver.js.map +1 -1
- package/dist/native/rsc/server/vite-handoff-rsc.js.map +1 -1
- package/dist/native/rsc/shared/key-headers.js +20 -0
- package/dist/native/rsc/shared/key-headers.js.map +1 -0
- package/dist/native/rsc/shared/outlet-decision.js.map +1 -1
- package/dist/native/ssr/client/outlet-content-cache.js +6 -26
- package/dist/native/ssr/client/outlet-content-cache.js.map +1 -1
- package/dist/native/ssr/client/outlet-scope-context.js.map +1 -1
- package/dist/native/ssr/client/segment-outlet.js +6 -19
- package/dist/native/ssr/client/segment-outlet.js.map +1 -1
- package/dist/native/ssr/manifest.json +1 -1
- package/dist/native/ssr/server/als-registry.js +0 -1
- package/dist/native/ssr/server/als-registry.js.map +1 -1
- package/dist/native/ssr/server/client-state-tree.js +1 -5
- package/dist/native/ssr/server/client-state-tree.js.map +1 -1
- package/dist/native/ssr/server/flight-source-node.js +2 -5
- package/dist/native/ssr/server/flight-source-node.js.map +1 -1
- package/dist/native/ssr/server/flight-source.js +0 -1
- package/dist/native/ssr/server/flight-source.js.map +1 -1
- package/dist/native/ssr/server/framework-stack-frames.js.map +1 -1
- package/dist/native/ssr/server/request-context.js +3 -3
- package/dist/native/ssr/server/request-context.js.map +1 -1
- package/dist/native/ssr/server/segment-lifetime/read-rule.js +25 -3
- package/dist/native/ssr/server/segment-lifetime/read-rule.js.map +1 -1
- package/dist/native/ssr/server/vite-handoff-rsc.js.map +1 -1
- package/dist/native/ssr/shared/key-headers.js +13 -0
- package/dist/native/ssr/shared/key-headers.js.map +1 -0
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/routing/route-options.d.ts.map +1 -1
- package/dist/routing/segment-keys.d.ts +3 -4
- package/dist/routing/segment-keys.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +2 -16
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/client-state-tree.d.ts +5 -11
- package/dist/server/client-state-tree.d.ts.map +1 -1
- package/dist/server/flight-source-node.d.ts +1 -6
- package/dist/server/flight-source-node.d.ts.map +1 -1
- package/dist/server/flight-source.d.ts +0 -27
- package/dist/server/flight-source.d.ts.map +1 -1
- package/dist/server/framework-stack-frames.d.ts +1 -4
- package/dist/server/framework-stack-frames.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +13 -23
- package/dist/server/internal.js.map +1 -1
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts +2 -2
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/rsc-entry/helpers.d.ts +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +0 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +2 -11
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/segment-lifetime/outlet-gate.d.ts +58 -0
- package/dist/server/segment-lifetime/outlet-gate.d.ts.map +1 -0
- package/dist/server/segment-lifetime/read-rule.d.ts +13 -3
- package/dist/server/segment-lifetime/read-rule.d.ts.map +1 -1
- package/dist/server/segment-lifetime/read-scope.d.ts +2 -1
- package/dist/server/segment-lifetime/read-scope.d.ts.map +1 -1
- package/dist/server/segment-lifetime/segment-key.d.ts +3 -0
- package/dist/server/segment-lifetime/segment-key.d.ts.map +1 -1
- package/dist/server/segment-lifetime/slot-outlets.d.ts +2 -2
- package/dist/server/segment-lifetime/slot-outlets.d.ts.map +1 -1
- package/dist/server/slot-resolver.d.ts +5 -5
- package/dist/server/slot-resolver.d.ts.map +1 -1
- package/dist/server/types.d.ts +8 -2
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/vite-handoff-rsc.d.ts +1 -10
- package/dist/server/vite-handoff-rsc.d.ts.map +1 -1
- package/dist/shared/key-headers.d.ts +13 -0
- package/dist/shared/key-headers.d.ts.map +1 -0
- package/dist/shared/outlet-decision.d.ts +13 -44
- package/dist/shared/outlet-decision.d.ts.map +1 -1
- package/dist/shared/payload-root.d.ts +1 -1
- package/dist/shared/segment-info.d.ts +3 -7
- package/dist/shared/segment-info.d.ts.map +1 -1
- package/docs/api/30-api-server.mdx +1 -1
- package/package.json +1 -1
- package/src/client/browser-entry/index.ts +0 -2
- package/src/client/browser-entry/router-init.ts +2 -4
- package/src/client/error-boundary.tsx +1 -1
- package/src/client/navigation-commit.ts +4 -18
- package/src/client/outlet-content-cache.ts +24 -62
- package/src/client/outlet-scope-context.ts +5 -5
- package/src/client/params-context.ts +1 -1
- package/src/client/router-types.ts +3 -14
- package/src/client/router.ts +0 -2
- package/src/client/rsc-fetch.ts +1 -1
- package/src/client/segment-cache.ts +2 -2
- package/src/client/segment-outlet.tsx +19 -51
- package/src/client/stale-segment.ts +2 -2
- package/src/config-types.ts +0 -17
- package/src/config-validation.ts +0 -1
- package/src/plugins/entries.ts +0 -1
- package/src/routing/route-options.ts +20 -4
- package/src/routing/scanner.ts +1 -1
- package/src/routing/segment-keys.ts +3 -4
- package/src/rsc-runtime/vendor-types.d.ts +1 -1
- package/src/server/als-registry.ts +2 -23
- package/src/server/client-state-tree.ts +7 -18
- package/src/server/flight-source-node.ts +1 -5
- package/src/server/flight-source.ts +1 -81
- package/src/server/framework-stack-frames.ts +1 -4
- package/src/server/request-context.ts +6 -5
- package/src/server/route-element-builder.ts +13 -14
- package/src/server/rsc-entry/helpers.ts +1 -1
- package/src/server/rsc-entry/index.ts +0 -3
- package/src/server/rsc-entry/render-route.ts +7 -54
- package/src/server/rsc-entry/revalidate-renderer.ts +0 -2
- package/src/server/rsc-entry/rsc-stream.ts +3 -23
- package/src/server/segment-lifetime/outlet-gate.ts +102 -0
- package/src/server/segment-lifetime/read-rule.ts +63 -6
- package/src/server/segment-lifetime/read-scope.ts +4 -2
- package/src/server/segment-lifetime/segment-key.ts +31 -3
- package/src/server/segment-lifetime/slot-outlets.ts +5 -5
- package/src/server/slot-resolver.ts +8 -8
- package/src/server/types.ts +8 -2
- package/src/server/vite-handoff-rsc.ts +1 -12
- package/src/shared/key-headers.ts +42 -0
- package/src/shared/outlet-decision.ts +13 -48
- package/src/shared/payload-root.ts +1 -1
- package/src/shared/segment-info.ts +3 -7
- package/dist/_chunks/actions-BCYVyoFl.js.map +0 -1
- package/dist/_chunks/chains-DPZAMMav.js +0 -1
- package/dist/_chunks/convention-lint-BfC_dAhZ.js.map +0 -1
- package/dist/_chunks/dev-server-3DNTXQV-.js +0 -1
- package/dist/_chunks/dev-server-3R6Bl9_R.js.map +0 -1
- package/dist/_chunks/error-boundary-Dfhxigko.js.map +0 -1
- package/dist/_chunks/flight-source-node-QOpWZATb.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/capture.js +0 -107
- package/dist/native/rsc/server/segment-hash/capture.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/outlet.js +0 -101
- package/dist/native/rsc/server/segment-hash/outlet.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/stream-tap.js +0 -139
- package/dist/native/rsc/server/segment-hash/stream-tap.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/value-hash.js +0 -171
- package/dist/native/rsc/server/segment-hash/value-hash.js.map +0 -1
- package/dist/native/ssr/server/segment-hash/value-hash.js +0 -162
- package/dist/native/ssr/server/segment-hash/value-hash.js.map +0 -1
- package/dist/server/segment-hash/capture.d.ts +0 -77
- package/dist/server/segment-hash/capture.d.ts.map +0 -1
- package/dist/server/segment-hash/outlet.d.ts +0 -93
- package/dist/server/segment-hash/outlet.d.ts.map +0 -1
- package/dist/server/segment-hash/stream-tap.d.ts +0 -49
- package/dist/server/segment-hash/stream-tap.d.ts.map +0 -1
- package/dist/server/segment-hash/value-hash.d.ts +0 -70
- package/dist/server/segment-hash/value-hash.d.ts.map +0 -1
- package/src/server/segment-hash/capture.ts +0 -232
- package/src/server/segment-hash/outlet.ts +0 -229
- package/src/server/segment-hash/stream-tap.ts +0 -244
- package/src/server/segment-hash/value-hash.ts +0 -338
|
@@ -340,29 +340,6 @@ export const prebuiltCaptureAls = getOrCreateAls<PrebuiltCaptureStore>(
|
|
|
340
340
|
Symbol.for('timber:prebuilt-capture-als')
|
|
341
341
|
);
|
|
342
342
|
|
|
343
|
-
// ─── Segment Hash Capture ─────────────────────────────────────────────────
|
|
344
|
-
// Used by: segment-hash/capture.ts, segment-hash/outlet.ts
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* One in-flight segment-hash capture render (design/52 §"Capture"). The
|
|
348
|
-
* outlet gate renders a nested segment as a bare hole there — its content
|
|
349
|
-
* belongs to its own hash.
|
|
350
|
-
*
|
|
351
|
-
* @internal — import via segment-hash/capture.ts
|
|
352
|
-
*/
|
|
353
|
-
export interface SegmentCaptureStore {
|
|
354
|
-
/**
|
|
355
|
-
* A nested outlet rendered here, as a hole: the opaque marker it carries in
|
|
356
|
-
* place of its decision (a Flight temporary reference).
|
|
357
|
-
*/
|
|
358
|
-
hole(segmentPath: string): import('../shared/outlet-decision.ts').CaptureHole;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/** @internal — import via segment-hash/capture.ts */
|
|
362
|
-
export const segmentCaptureAls = getOrCreateAls<SegmentCaptureStore>(
|
|
363
|
-
Symbol.for('timber:segment-capture-als')
|
|
364
|
-
);
|
|
365
|
-
|
|
366
343
|
// ─── 'document' segment read scope ────────────────────────────────────────
|
|
367
344
|
// Used by: segment-lifetime/read-scope.ts (set), request-context.ts and
|
|
368
345
|
// cookie-context.ts (checked by every request-input accessor).
|
|
@@ -385,6 +362,8 @@ export interface DocumentReadScope {
|
|
|
385
362
|
* holds: a keyed cookie may be read only through that definition.
|
|
386
363
|
*/
|
|
387
364
|
cookies: ReadonlyMap<string, unknown>;
|
|
365
|
+
/** The key's header names, lowercased. */
|
|
366
|
+
headers: ReadonlySet<string>;
|
|
388
367
|
}
|
|
389
368
|
|
|
390
369
|
/** @internal — run and read via segment-lifetime/read-scope.ts */
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parsing of the client's `X-Timber-State-Tree` request header.
|
|
3
3
|
*
|
|
4
|
-
* The header carries
|
|
4
|
+
* The header carries two unrelated things:
|
|
5
5
|
*
|
|
6
|
-
* - `hashes` — the segment hashes the client holds content for, by outlet
|
|
7
|
-
* path. The outlet gates compare them with a capture of each segment and
|
|
8
|
-
* skip the ones that match (design/52-segment-hash-dedupe.md). Read only
|
|
9
|
-
* when the app opted into `clientSegmentCache`.
|
|
10
6
|
* - `documents` — the key digests of the `'document'` segments the client
|
|
11
7
|
* holds content for, by outlet path. An outlet gate skips a `'document'`
|
|
12
8
|
* segment without rendering it when the digest verifies against this
|
|
@@ -16,20 +12,17 @@
|
|
|
16
12
|
* now, for interception scoping (design/07-routing.md §"Intercepting
|
|
17
13
|
* Routes", TIM-1282).
|
|
18
14
|
*
|
|
19
|
-
*
|
|
20
|
-
* send a skip for content the client claims to hold; the client checks every
|
|
21
|
-
* against the
|
|
22
|
-
* regardless. See design/13-security.md §"State tree manipulation".
|
|
15
|
+
* Neither is a security input. A forged digest can only make the server
|
|
16
|
+
* send a skip for content the client claims to hold; the client checks every
|
|
17
|
+
* skip against the digest of what it actually holds, and every `access.ts`
|
|
18
|
+
* runs regardless. See design/13-security.md §"State tree manipulation".
|
|
23
19
|
*/
|
|
24
20
|
|
|
25
|
-
import { SEGMENT_HASH_LENGTH } from './segment-hash/value-hash.ts';
|
|
26
21
|
import { KEY_DIGEST_SHAPE } from './segment-lifetime/key-digest.ts';
|
|
27
22
|
import { swallow } from './logger.ts';
|
|
28
23
|
|
|
29
24
|
/** The parsed header. */
|
|
30
25
|
export interface ClientStateTree {
|
|
31
|
-
/** Segment hashes by outlet path, or null when none were sent. */
|
|
32
|
-
hashes: ReadonlyMap<string, string> | null;
|
|
33
26
|
/** `'document'` key digests by outlet path, or null when none were sent. */
|
|
34
27
|
documents: ReadonlyMap<string, string> | null;
|
|
35
28
|
/** Directory paths of the mounted segments, or null when none were sent. */
|
|
@@ -42,8 +35,6 @@ export interface ClientStateTree {
|
|
|
42
35
|
*/
|
|
43
36
|
const MAX_ENTRIES = 512;
|
|
44
37
|
|
|
45
|
-
const HASH_SHAPE = new RegExp(`^[A-Za-z0-9_-]{${SEGMENT_HASH_LENGTH}}$`);
|
|
46
|
-
|
|
47
38
|
/**
|
|
48
39
|
* Parse `X-Timber-State-Tree`. Null when the header is missing, malformed, or
|
|
49
40
|
* says nothing. Entries of the wrong shape are dropped, not trusted.
|
|
@@ -52,7 +43,7 @@ export function parseClientStateTree(req: Request): ClientStateTree | null {
|
|
|
52
43
|
const header = req.headers.get('X-Timber-State-Tree');
|
|
53
44
|
if (!header) return null;
|
|
54
45
|
|
|
55
|
-
let parsed: {
|
|
46
|
+
let parsed: { documents?: unknown; treePaths?: unknown };
|
|
56
47
|
try {
|
|
57
48
|
parsed = JSON.parse(header) as typeof parsed;
|
|
58
49
|
} catch (err) {
|
|
@@ -61,16 +52,14 @@ export function parseClientStateTree(req: Request): ClientStateTree | null {
|
|
|
61
52
|
}
|
|
62
53
|
if (!parsed || typeof parsed !== 'object') return null;
|
|
63
54
|
|
|
64
|
-
const hashes = readTokenMap(parsed.hashes, HASH_SHAPE);
|
|
65
55
|
const documents = readTokenMap(parsed.documents, KEY_DIGEST_SHAPE);
|
|
66
56
|
|
|
67
57
|
const treePaths = Array.isArray(parsed.treePaths)
|
|
68
58
|
? new Set(parsed.treePaths.filter((p): p is string => typeof p === 'string'))
|
|
69
59
|
: new Set<string>();
|
|
70
60
|
|
|
71
|
-
if (
|
|
61
|
+
if (documents.size === 0 && treePaths.size === 0) return null;
|
|
72
62
|
return {
|
|
73
|
-
hashes: hashes.size > 0 ? hashes : null,
|
|
74
63
|
documents: documents.size > 0 ? documents : null,
|
|
75
64
|
treePaths: treePaths.size > 0 ? treePaths : null,
|
|
76
65
|
};
|
|
@@ -73,8 +73,6 @@ export interface NodeFlightAbort {
|
|
|
73
73
|
signal?: AbortSignal;
|
|
74
74
|
/** Abort with a `RenderTimeoutError` after this long, if still rendering. */
|
|
75
75
|
timeoutMs?: number;
|
|
76
|
-
/** Shown every chunk, and the end (`FlightRenderOptions.tap`). */
|
|
77
|
-
tap?: { observe(chunk: Uint8Array): void; end(): void };
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
/**
|
|
@@ -95,7 +93,7 @@ export interface NodeFlightAbort {
|
|
|
95
93
|
*/
|
|
96
94
|
export function pipeFlightToNode(
|
|
97
95
|
flight: PipeableFlight,
|
|
98
|
-
{ signal, timeoutMs
|
|
96
|
+
{ signal, timeoutMs }: NodeFlightAbort
|
|
99
97
|
): Readable {
|
|
100
98
|
const scope = new AbortController();
|
|
101
99
|
const timer =
|
|
@@ -109,11 +107,9 @@ export function pipeFlightToNode(
|
|
|
109
107
|
objectMode: true,
|
|
110
108
|
transform(chunk: NodeFlightChunk, _encoding, callback) {
|
|
111
109
|
const out = typeof chunk === 'string' ? chunk.toWellFormed() : chunk;
|
|
112
|
-
tap?.observe(typeof out === 'string' ? Buffer.from(out) : out);
|
|
113
110
|
callback(null, out);
|
|
114
111
|
},
|
|
115
112
|
destroy(error, callback) {
|
|
116
|
-
tap?.end();
|
|
117
113
|
endScope(scope);
|
|
118
114
|
clearTimeout(timer);
|
|
119
115
|
// Flight ended the stream (React calls `end()` once the render is
|
|
@@ -25,7 +25,6 @@ import type { Readable } from 'node:stream';
|
|
|
25
25
|
import { isAppStackFrame } from './framework-stack-frames.ts';
|
|
26
26
|
import { nodeStreamsPlatform } from './node-streams-platform.ts';
|
|
27
27
|
import { releaseReason } from './render-utils.ts';
|
|
28
|
-
import { withTimeout } from './render-timeout.ts';
|
|
29
28
|
import {
|
|
30
29
|
concatBytes,
|
|
31
30
|
drainWithDeadline,
|
|
@@ -76,30 +75,6 @@ export interface FlightRenderOptions {
|
|
|
76
75
|
* themselves.
|
|
77
76
|
*/
|
|
78
77
|
timeoutMs?: number;
|
|
79
|
-
/**
|
|
80
|
-
* Observes every chunk the render writes, and its end — the segment hash
|
|
81
|
-
* tap (segment-hash/stream-tap.ts). Chunks pass through unchanged.
|
|
82
|
-
*/
|
|
83
|
-
tap?: FlightTap;
|
|
84
|
-
/**
|
|
85
|
-
* Values to write as opaque references (`$T<id>`) instead of serializing —
|
|
86
|
-
* Flight's temporary references, keyed by the value. A segment-hash capture
|
|
87
|
-
* writes its nested outlets this way so decoding it can put the live outlet
|
|
88
|
-
* back (segment-hash/capture.ts).
|
|
89
|
-
*/
|
|
90
|
-
temporaryReferences?: WeakMap<object, string>;
|
|
91
|
-
/**
|
|
92
|
-
* Prefix for the ids `useId()` returns in server components. Each render
|
|
93
|
-
* counts from zero, so two renders whose output shares one document — the
|
|
94
|
-
* main render and a segment-hash capture — need different prefixes.
|
|
95
|
-
*/
|
|
96
|
-
identifierPrefix?: string;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** An observer of a Flight render's output. */
|
|
100
|
-
export interface FlightTap {
|
|
101
|
-
observe(chunk: Uint8Array): void;
|
|
102
|
-
end(): void;
|
|
103
78
|
}
|
|
104
79
|
|
|
105
80
|
/**
|
|
@@ -125,8 +100,6 @@ export type WebFlightRenderer = (
|
|
|
125
100
|
options?: {
|
|
126
101
|
onError?: (error: unknown) => string | void;
|
|
127
102
|
signal?: AbortSignal;
|
|
128
|
-
temporaryReferences?: WeakMap<object, string>;
|
|
129
|
-
identifierPrefix?: string;
|
|
130
103
|
filterStackFrame?: (url: string, functionName: string) => boolean;
|
|
131
104
|
}
|
|
132
105
|
) => ReadableStream<Uint8Array>;
|
|
@@ -136,8 +109,6 @@ export type NodeFlightRenderer = (
|
|
|
136
109
|
model: unknown,
|
|
137
110
|
options?: {
|
|
138
111
|
onError?: (error: unknown) => string | void;
|
|
139
|
-
temporaryReferences?: WeakMap<object, string>;
|
|
140
|
-
identifierPrefix?: string;
|
|
141
112
|
filterStackFrame?: (url: string, functionName: string) => boolean;
|
|
142
113
|
}
|
|
143
114
|
) => import('./flight-source-node.ts').PipeableFlight;
|
|
@@ -164,14 +135,11 @@ export function createRenderFlight(
|
|
|
164
135
|
stream: pipeFlightToNode(
|
|
165
136
|
node(model, {
|
|
166
137
|
onError: options.onError,
|
|
167
|
-
temporaryReferences: options.temporaryReferences,
|
|
168
|
-
identifierPrefix: options.identifierPrefix,
|
|
169
138
|
filterStackFrame: isAppStackFrame,
|
|
170
139
|
}),
|
|
171
140
|
{
|
|
172
141
|
signal: options.signal,
|
|
173
142
|
timeoutMs: options.timeoutMs ?? defaultRenderTimeoutMs,
|
|
174
|
-
tap: options.tap,
|
|
175
143
|
}
|
|
176
144
|
),
|
|
177
145
|
});
|
|
@@ -180,60 +148,12 @@ export function createRenderFlight(
|
|
|
180
148
|
const stream = web(model, {
|
|
181
149
|
onError: options.onError,
|
|
182
150
|
signal: options.signal,
|
|
183
|
-
temporaryReferences: options.temporaryReferences,
|
|
184
|
-
identifierPrefix: options.identifierPrefix,
|
|
185
151
|
filterStackFrame: isAppStackFrame,
|
|
186
152
|
});
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
kind: 'web',
|
|
190
|
-
stream: options.tap ? tapWebFlight(stream, options.tap, timeoutMs) : stream,
|
|
191
|
-
};
|
|
153
|
+
return { kind: 'web', stream };
|
|
192
154
|
};
|
|
193
155
|
}
|
|
194
156
|
|
|
195
|
-
/**
|
|
196
|
-
* Pass a Web Flight stream through unchanged, showing each chunk to `tap`,
|
|
197
|
-
* and its end — whether it finished, failed, or was cancelled.
|
|
198
|
-
*/
|
|
199
|
-
function tapWebFlight(
|
|
200
|
-
source: ReadableStream<Uint8Array>,
|
|
201
|
-
tap: FlightTap,
|
|
202
|
-
timeoutMs: number | undefined
|
|
203
|
-
): ReadableStream<Uint8Array> {
|
|
204
|
-
const reader = source.getReader();
|
|
205
|
-
// The wrapper reads upstream, so its reads are guarded like every stream
|
|
206
|
-
// read (design/02 §"Always Timeout-Guard Stream Reads"): one deadline for
|
|
207
|
-
// the whole render, after which the upstream is cancelled.
|
|
208
|
-
const deadline = timeoutMs === undefined ? undefined : Date.now() + timeoutMs;
|
|
209
|
-
return new ReadableStream<Uint8Array>({
|
|
210
|
-
async pull(controller) {
|
|
211
|
-
try {
|
|
212
|
-
const read = reader.read();
|
|
213
|
-
const result =
|
|
214
|
-
deadline === undefined
|
|
215
|
-
? await read
|
|
216
|
-
: await withTimeout(read, Math.max(0, deadline - Date.now()), 'Flight render');
|
|
217
|
-
if (result.done) {
|
|
218
|
-
tap.end();
|
|
219
|
-
controller.close();
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
tap.observe(result.value);
|
|
223
|
-
controller.enqueue(result.value);
|
|
224
|
-
} catch (error) {
|
|
225
|
-
tap.end();
|
|
226
|
-
reader.cancel(releaseReason(error)).catch(() => {});
|
|
227
|
-
controller.error(error);
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
cancel(reason) {
|
|
231
|
-
tap.end();
|
|
232
|
-
return reader.cancel(releaseReason(reason));
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
157
|
// ─── Reading ────────────────────────────────────────────────────────────────
|
|
238
158
|
|
|
239
159
|
/** A pull reader over a Flight source, of either kind. */
|
|
@@ -7,10 +7,7 @@
|
|
|
7
7
|
* `node_modules` as app code. Installed, timber sits in `node_modules`; run
|
|
8
8
|
* from source (this repo, its examples, a linked checkout) its own files would
|
|
9
9
|
* count as app code, and its internal awaits would be written into every dev
|
|
10
|
-
* payload.
|
|
11
|
-
* segment's decoded content, so a skipped segment's content would be sent as
|
|
12
|
-
* the debug value of the read a decision chained through
|
|
13
|
-
* (design/52-segment-hash-dedupe.md §"Capture").
|
|
10
|
+
* payload.
|
|
14
11
|
*
|
|
15
12
|
* Next.js passes its own `filterStackFrameDEV` for the same reason; its code
|
|
16
13
|
* is always in `node_modules`, so it filters by source map instead.
|
|
@@ -36,6 +36,8 @@ import { runWithReactCacheScope, type ReactCacheScope } from './react-cache-scop
|
|
|
36
36
|
import {
|
|
37
37
|
assertSearchParamsRead,
|
|
38
38
|
assertUnscopedRead,
|
|
39
|
+
currentReadScope,
|
|
40
|
+
keyedHeaders,
|
|
39
41
|
scopedParams,
|
|
40
42
|
} from './segment-lifetime/read-rule.ts';
|
|
41
43
|
import type { ReactFormState } from 'react-dom/client';
|
|
@@ -59,11 +61,10 @@ export function getHeaders(): ReadonlyHeaders {
|
|
|
59
61
|
'It can only be used in middleware, access checks, server components, and server actions.'
|
|
60
62
|
);
|
|
61
63
|
}
|
|
62
|
-
// A 'document' segment may
|
|
63
|
-
// which
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return store.headers;
|
|
64
|
+
// A 'document' segment may read only the headers in its key — never all of
|
|
65
|
+
// them, which would include the pathname (design/53).
|
|
66
|
+
const scope = currentReadScope();
|
|
67
|
+
return scope ? keyedHeaders(store.headers, scope) : store.headers;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/**
|
|
@@ -47,7 +47,7 @@ import { documentOutletFor, pathParamNames } from './segment-lifetime/document-o
|
|
|
47
47
|
import { getSegmentParams } from './request-context.ts';
|
|
48
48
|
import { inReadScope, readScopeFor } from './segment-lifetime/read-scope.ts';
|
|
49
49
|
import type { ServerComponent } from './subtree-walk.ts';
|
|
50
|
-
import { outletGate, type OutletSpec, type
|
|
50
|
+
import { outletGate, type OutletSpec, type SegmentRender } from './segment-lifetime/outlet-gate.ts';
|
|
51
51
|
import { METADATA_OUTLET_PATH } from '../shared/outlet-decision.ts';
|
|
52
52
|
import { setFirstDeniedSegmentIndex } from './deny-boundary.ts';
|
|
53
53
|
import { loadModule, type ManifestLoader } from './safe-load.ts';
|
|
@@ -187,7 +187,7 @@ export async function buildRouteElement(
|
|
|
187
187
|
req: Request,
|
|
188
188
|
match: RouteMatch,
|
|
189
189
|
interception: InterceptionContext | undefined,
|
|
190
|
-
render:
|
|
190
|
+
render: SegmentRender,
|
|
191
191
|
metadataRouteHashes?: Record<string, string>
|
|
192
192
|
): Promise<RouteElementResult> {
|
|
193
193
|
const segments = match.segments;
|
|
@@ -331,7 +331,7 @@ export async function buildRouteElement(
|
|
|
331
331
|
mainParams
|
|
332
332
|
),
|
|
333
333
|
};
|
|
334
|
-
element = outletGate(pageOutlet
|
|
334
|
+
element = outletGate(pageOutlet);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
// Metadata is its own outlet, a SIBLING of the page rather than a wrapper.
|
|
@@ -340,8 +340,7 @@ export async function buildRouteElement(
|
|
|
340
340
|
// <head> regardless of tree position. Both resolve before onShellReady
|
|
341
341
|
// (outside Suspense), but they overlap. As its own outlet, a title that
|
|
342
342
|
// changes does not resend the page beside it, and a page's title does not
|
|
343
|
-
// land in the output of
|
|
344
|
-
// own unit"). See TIM-1363, TIM-1367, design/16-metadata.md.
|
|
343
|
+
// land in the output of a 'document' layout above it, which may be skipped. See TIM-1363, TIM-1367, design/16-metadata.md.
|
|
345
344
|
const metadataOutlet: OutletSpec = {
|
|
346
345
|
segmentPath: METADATA_OUTLET_PATH,
|
|
347
346
|
content: h(MetadataHead, {
|
|
@@ -352,7 +351,7 @@ export async function buildRouteElement(
|
|
|
352
351
|
}),
|
|
353
352
|
nested: [],
|
|
354
353
|
};
|
|
355
|
-
element = h(Fragment, null, outletGate(metadataOutlet
|
|
354
|
+
element = h(Fragment, null, outletGate(metadataOutlet), element);
|
|
356
355
|
|
|
357
356
|
// Build a lookup of layout components by segment for O(1) access.
|
|
358
357
|
const layoutBySegment = new Map(
|
|
@@ -362,7 +361,7 @@ export async function buildRouteElement(
|
|
|
362
361
|
// The outlets built so far that no outlet built so far contains — the ones
|
|
363
362
|
// the next outlet out will hold directly. A skipped outlet carries their
|
|
364
363
|
// decisions, because the client's cached copy of it still holds the old
|
|
365
|
-
// ones (segment-
|
|
364
|
+
// ones (segment-lifetime/outlet-gate.ts).
|
|
366
365
|
let unclaimedOutlets: OutletSpec[] = pageOutlet ? [metadataOutlet, pageOutlet] : [metadataOutlet];
|
|
367
366
|
|
|
368
367
|
for (let i = segments.length - 1; i >= 0; i--) {
|
|
@@ -411,8 +410,8 @@ export async function buildRouteElement(
|
|
|
411
410
|
const layoutOutletPath = layoutLifetime ? layoutOutletKey(segmentTreePaths[i]) : segmentId;
|
|
412
411
|
|
|
413
412
|
// Everything this layout receives as `children` is one outlet, and the
|
|
414
|
-
// layout's own outlet below is another:
|
|
415
|
-
// chrome, not what renders under it.
|
|
413
|
+
// layout's own outlet below is another: skipping a 'document' layout
|
|
414
|
+
// skips its chrome, not what renders under it.
|
|
416
415
|
const childrenOutlet: OutletSpec = {
|
|
417
416
|
segmentPath: childrenOutletKey(segmentId),
|
|
418
417
|
content: element,
|
|
@@ -435,7 +434,7 @@ export async function buildRouteElement(
|
|
|
435
434
|
|
|
436
435
|
const segmentPath = computeLayoutSegmentPath(segments, i, match);
|
|
437
436
|
const parallelRouteKeys = Object.keys(segment.slots ?? {});
|
|
438
|
-
const layoutProps = { ...slots.props, children: outletGate(childrenOutlet
|
|
437
|
+
const layoutProps = { ...slots.props, children: outletGate(childrenOutlet) };
|
|
439
438
|
|
|
440
439
|
// Build the layout element.
|
|
441
440
|
// Keep the descendant tree in a SERVER layout's children prop. Moving it
|
|
@@ -526,7 +525,7 @@ export async function buildRouteElement(
|
|
|
526
525
|
segmentPath.length
|
|
527
526
|
),
|
|
528
527
|
};
|
|
529
|
-
element = outletGate(layoutOutlet
|
|
528
|
+
element = outletGate(layoutOutlet);
|
|
530
529
|
unclaimedOutlets = [layoutOutlet];
|
|
531
530
|
}
|
|
532
531
|
|
|
@@ -536,9 +535,9 @@ export async function buildRouteElement(
|
|
|
536
535
|
// exactly once, during render, inside React.cache scope — layouts
|
|
537
536
|
// share the cache. See TIM-1363, design/04-authorization.md.
|
|
538
537
|
//
|
|
539
|
-
// It sits in the enclosing outlet's content,
|
|
540
|
-
//
|
|
541
|
-
//
|
|
538
|
+
// It sits in the enclosing outlet's content, outside a 'document'
|
|
539
|
+
// layout's own outlet, so it runs on every request even when that layout
|
|
540
|
+
// is skipped (design/53 §"access.ts and metadata still run").
|
|
542
541
|
const accessFn = gateFor(i);
|
|
543
542
|
if (accessFn) {
|
|
544
543
|
element = wrapAccessGate(
|
|
@@ -15,7 +15,7 @@ import type { SegmentInfo } from '../../shared/segment-info.ts';
|
|
|
15
15
|
* interception scoping (design/07-routing.md §"Intercepting Routes").
|
|
16
16
|
*
|
|
17
17
|
* Nothing here is about caching — what the client may reuse is decided by
|
|
18
|
-
*
|
|
18
|
+
* the outlet decisions in the payload itself (design/53-segment-lifetime.md).
|
|
19
19
|
*/
|
|
20
20
|
export function buildSegmentInfo(
|
|
21
21
|
segments: ManifestSegmentNode[],
|
|
@@ -266,8 +266,6 @@ async function createRequestHandler(manifest: typeof routeManifest, runtimeConfi
|
|
|
266
266
|
| { disabled: boolean; enableHMRInDev: boolean }
|
|
267
267
|
| undefined;
|
|
268
268
|
const clientJsDisabled = clientJsConfig?.disabled ?? false;
|
|
269
|
-
const clientSegmentCache =
|
|
270
|
-
((runtimeConfig as Record<string, unknown>).clientSegmentCache as boolean) ?? false;
|
|
271
269
|
// Written by `plugins/entries.ts` as exactly 'request' or 'document'.
|
|
272
270
|
const defaultLayoutLifetime: SegmentLifetime =
|
|
273
271
|
(runtimeConfig as Record<string, unknown>).defaultLayoutLifetime === 'document'
|
|
@@ -393,7 +391,6 @@ async function createRequestHandler(manifest: typeof routeManifest, runtimeConfi
|
|
|
393
391
|
{
|
|
394
392
|
clientBootstrap,
|
|
395
393
|
clientJsDisabled,
|
|
396
|
-
clientSegmentCache,
|
|
397
394
|
keyDigestSigner,
|
|
398
395
|
defaultLayoutLifetime,
|
|
399
396
|
renderDenyFallback,
|
|
@@ -32,9 +32,7 @@ import { DenySignal } from '../primitives.ts';
|
|
|
32
32
|
import { buildRouteElement, NoPageComponentError } from '../route-element-builder.ts';
|
|
33
33
|
import { recordTiming } from '../server-timing.ts';
|
|
34
34
|
import { parseClientStateTree } from '../client-state-tree.ts';
|
|
35
|
-
import {
|
|
36
|
-
import { createFromReadableStream } from '../vite-handoff-rsc.ts';
|
|
37
|
-
import { createSegmentHashTap } from '../segment-hash/stream-tap.ts';
|
|
35
|
+
import type { SegmentRender } from '../segment-lifetime/outlet-gate.ts';
|
|
38
36
|
import type { KeyDigestSigner } from '../segment-lifetime/key-digest.ts';
|
|
39
37
|
import type { SegmentLifetime } from '../types.ts';
|
|
40
38
|
|
|
@@ -55,7 +53,6 @@ import { renderSsrResponse } from './ssr-renderer.ts';
|
|
|
55
53
|
export interface RenderRouteDeps {
|
|
56
54
|
clientBootstrap: ClientBootstrapConfig;
|
|
57
55
|
clientJsDisabled: boolean;
|
|
58
|
-
clientSegmentCache: boolean;
|
|
59
56
|
/**
|
|
60
57
|
* Issues and checks key digests for 'document' segments
|
|
61
58
|
* (design/53-segment-lifetime.md); null when client JavaScript is disabled,
|
|
@@ -102,43 +99,15 @@ export async function renderRoute(
|
|
|
102
99
|
return handleApiRoute(req, segments, responseHeaders);
|
|
103
100
|
}
|
|
104
101
|
|
|
105
|
-
// Segment hash dedupe (design/52-segment-hash-dedupe.md), when the app
|
|
106
|
-
// opted in. Every render that can reach a client router hashes its live
|
|
107
|
-
// segments, document requests included — the client records those hashes
|
|
108
|
-
// as it hydrates. Only a navigation request carries hashes to compare
|
|
109
|
-
// against (`X-Timber-State-Tree`), so only it can skip.
|
|
110
|
-
const hashing = deps.clientSegmentCache && !clientJsDisabled;
|
|
111
|
-
const tap = hashing
|
|
112
|
-
? createSegmentHashTap({
|
|
113
|
-
timeoutMs: deps.renderTimeoutMs,
|
|
114
|
-
isOutlet: isOutletType,
|
|
115
|
-
decode: (stream) => createFromReadableStream(stream),
|
|
116
|
-
})
|
|
117
|
-
: null;
|
|
118
|
-
// A capture reports through the main render's error handler, which exists
|
|
119
|
-
// only once the main render starts — captures start inside it. The digests
|
|
120
|
-
// it hands out are remembered, so the main render passes a decoded error
|
|
121
|
-
// row through instead of reporting it a second time.
|
|
122
|
-
const relayedDigests = new Set<string>();
|
|
123
|
-
let mainOnError: ((error: unknown) => string | void) | null = null;
|
|
124
102
|
// Only a navigation carries the client's state; a document request renders
|
|
125
|
-
// every segment and the client records what it hydrates.
|
|
103
|
+
// every segment and the client records what it hydrates. A 'document'
|
|
104
|
+
// segment is skipped when the client holds it under the current key
|
|
105
|
+
// (design/53-segment-lifetime.md).
|
|
126
106
|
const clientState = isRscRequest(req) ? parseClientStateTree(req) : null;
|
|
127
107
|
const signer = clientJsDisabled ? null : deps.keyDigestSigner;
|
|
128
|
-
const
|
|
129
|
-
clientHashes: hashing ? (clientState?.hashes ?? null) : null,
|
|
130
|
-
// 'document' segments are skipped when the client holds them under the
|
|
131
|
-
// current key — whether or not the app opted into hashing.
|
|
108
|
+
const segmentRender: SegmentRender = {
|
|
132
109
|
documents: signer ? { client: clientState?.documents ?? null, signer } : null,
|
|
133
110
|
defaultLayoutLifetime: deps.defaultLayoutLifetime,
|
|
134
|
-
tap,
|
|
135
|
-
captureTimeoutMs: deps.renderTimeoutMs,
|
|
136
|
-
signal: req.signal,
|
|
137
|
-
onCaptureError(error) {
|
|
138
|
-
const digest = mainOnError?.(error);
|
|
139
|
-
if (typeof digest === 'string') relayedDigests.add(digest);
|
|
140
|
-
return digest;
|
|
141
|
-
},
|
|
142
111
|
};
|
|
143
112
|
|
|
144
113
|
// Build the React element tree — runs access checks eagerly to gate
|
|
@@ -153,7 +122,7 @@ export async function renderRoute(
|
|
|
153
122
|
req,
|
|
154
123
|
match,
|
|
155
124
|
interception,
|
|
156
|
-
|
|
125
|
+
segmentRender,
|
|
157
126
|
buildManifest.metadataRouteHashes
|
|
158
127
|
);
|
|
159
128
|
} catch (error) {
|
|
@@ -231,23 +200,7 @@ export async function renderRoute(
|
|
|
231
200
|
|
|
232
201
|
// Render to RSC Flight stream with signal tracking.
|
|
233
202
|
const _rscStart = performance.now();
|
|
234
|
-
const { rscStream, signals
|
|
235
|
-
payload,
|
|
236
|
-
req,
|
|
237
|
-
deps.renderTimeoutMs,
|
|
238
|
-
leafDenyChain,
|
|
239
|
-
tap ?? undefined,
|
|
240
|
-
relayedDigests
|
|
241
|
-
);
|
|
242
|
-
// Released when the render ends: the outlet gates close over this handler,
|
|
243
|
-
// and dev keeps finished render's components reachable long enough that a
|
|
244
|
-
// handler still set here held every request (dev-request-retention).
|
|
245
|
-
if (tap) {
|
|
246
|
-
mainOnError = onError;
|
|
247
|
-
tap.onEnd(() => {
|
|
248
|
-
mainOnError = null;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
203
|
+
const { rscStream, signals } = renderRscStream(payload, req, deps.renderTimeoutMs, leafDenyChain);
|
|
251
204
|
|
|
252
205
|
recordTiming({
|
|
253
206
|
name: 'rsc-init',
|
|
@@ -47,7 +47,6 @@ import {
|
|
|
47
47
|
import type { CoercedParams } from '../../shared/param-value.ts';
|
|
48
48
|
|
|
49
49
|
import { runMiddlewareForAction } from './action-middleware-runner.ts';
|
|
50
|
-
import { NO_SEGMENT_HASHING } from '../segment-hash/outlet.ts';
|
|
51
50
|
import type { KeyDigestSigner } from '../segment-lifetime/key-digest.ts';
|
|
52
51
|
import type { SegmentLifetime } from '../types.ts';
|
|
53
52
|
import { RSC_CONTENT_TYPE } from '../../shared/rsc-media-type.ts';
|
|
@@ -351,7 +350,6 @@ export function createRevalidateRendererFactory(
|
|
|
351
350
|
match,
|
|
352
351
|
undefined,
|
|
353
352
|
{
|
|
354
|
-
...NO_SEGMENT_HASHING,
|
|
355
353
|
documents: deps.keyDigestSigner ? { client: null, signer: deps.keyDigestSigner } : null,
|
|
356
354
|
defaultLayoutLifetime: deps.defaultLayoutLifetime,
|
|
357
355
|
},
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { renderFlight } from '../vite-handoff-rsc.ts';
|
|
14
|
-
import type { FlightSource
|
|
14
|
+
import type { FlightSource } from '../flight-source.ts';
|
|
15
15
|
import type { RscPayloadRoot } from '../../shared/payload-root.ts';
|
|
16
16
|
import { encodeErrorDigest } from '../../shared/error-digest.ts';
|
|
17
17
|
|
|
@@ -31,8 +31,6 @@ import { isDebug } from '../debug.ts';
|
|
|
31
31
|
export interface RscStreamResult {
|
|
32
32
|
rscStream: FlightSource;
|
|
33
33
|
signals: RenderSignals;
|
|
34
|
-
/** The render's error handler — segment-hash captures report through it. */
|
|
35
|
-
onError: (error: unknown) => string | void;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
/**
|
|
@@ -54,28 +52,11 @@ export function renderRscStream(
|
|
|
54
52
|
payload: RscPayloadRoot,
|
|
55
53
|
req: Request,
|
|
56
54
|
renderTimeoutMs: number,
|
|
57
|
-
leafDenyChain?: DenyPageEntry[]
|
|
58
|
-
tap?: FlightTap,
|
|
59
|
-
/**
|
|
60
|
-
* Digests a segment-hash capture already produced through this handler. A
|
|
61
|
-
* capture's error row decoded into the live content reaches this render
|
|
62
|
-
* again as an error carrying that digest: pass it through, it has been
|
|
63
|
-
* reported and signalled once already.
|
|
64
|
-
*/
|
|
65
|
-
relayedDigests?: ReadonlySet<string>
|
|
55
|
+
leafDenyChain?: DenyPageEntry[]
|
|
66
56
|
): RscStreamResult {
|
|
67
57
|
const recorder = createSignalRecorder();
|
|
68
58
|
|
|
69
59
|
const onError = (error: unknown): string | void => {
|
|
70
|
-
if (
|
|
71
|
-
typeof error === 'object' &&
|
|
72
|
-
error !== null &&
|
|
73
|
-
'digest' in error &&
|
|
74
|
-
typeof error.digest === 'string' &&
|
|
75
|
-
relayedDigests?.has(error.digest)
|
|
76
|
-
) {
|
|
77
|
-
return error.digest;
|
|
78
|
-
}
|
|
79
60
|
// Connection abort (user refreshed or navigated away) — suppress.
|
|
80
61
|
// Not an application error; no need to track or log.
|
|
81
62
|
if (isAbortError(error) || req.signal?.aborted) return;
|
|
@@ -179,11 +160,10 @@ export function renderRscStream(
|
|
|
179
160
|
const rscStream = renderFlight(payload, {
|
|
180
161
|
signal: req.signal,
|
|
181
162
|
timeoutMs: renderTimeoutMs,
|
|
182
|
-
tap,
|
|
183
163
|
onError,
|
|
184
164
|
});
|
|
185
165
|
|
|
186
|
-
return { rscStream, signals: recorder.signals
|
|
166
|
+
return { rscStream, signals: recorder.signals };
|
|
187
167
|
}
|
|
188
168
|
|
|
189
169
|
/** Log and report an unhandled render error; the ID it was logged with. */
|