@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
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The outlet gate: renders one segment as a `SegmentOutlet` whose decision is
|
|
3
|
-
* either its live content or a skip.
|
|
4
|
-
*
|
|
5
|
-
* Every segment renders on every navigation; access runs for every one. What
|
|
6
|
-
* hash dedupe saves is bytes: when the client advertised a hash for a segment,
|
|
7
|
-
* the gate captures the segment (capture.ts), and if the capture's hash
|
|
8
|
-
* equals the client's, the segment is sent as a skip — the client keeps the
|
|
9
|
-
* content it holds. Otherwise the live content is sent with a hash the client
|
|
10
|
-
* stores beside it (stream-tap.ts). Nothing is predicted: a skip happens only
|
|
11
|
-
* when a render the server just ran produced exactly what the client holds.
|
|
12
|
-
*
|
|
13
|
-
* A skip carries the decisions of the segments nested directly inside it —
|
|
14
|
-
* only those the capture rendered as holes. Their access gates ran in the
|
|
15
|
-
* capture; a nested gate that denied rendered its deny page instead of the
|
|
16
|
-
* hole, so its segment is never decided, never rendered, never sent.
|
|
17
|
-
*
|
|
18
|
-
* A `'document'` segment (design/53-segment-lifetime.md) is decided before
|
|
19
|
-
* any of that, and never captured: when the client holds content rendered
|
|
20
|
-
* under the current key digest, the segment is skipped **without rendering**,
|
|
21
|
-
* and its nested outlets are decided as if it had rendered — lifetime does
|
|
22
|
-
* not cascade. Otherwise it is sent live with the digest it rendered under.
|
|
23
|
-
*
|
|
24
|
-
* See design/52-segment-hash-dedupe.md §"Mechanism".
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { createElement, type ReactElement, type ReactNode } from 'react';
|
|
28
|
-
import type { OutletDecision, OutletDecisionValue } from '../../shared/outlet-decision.ts';
|
|
29
|
-
import { clientComponents } from '../vite-handoff-rsc.ts';
|
|
30
|
-
import { stripReferenceCacheTag } from './value-hash.ts';
|
|
31
|
-
import { captureHoleMarker, captureSegment, type SegmentCapture } from './capture.ts';
|
|
32
|
-
import type { SegmentHashTap } from './stream-tap.ts';
|
|
33
|
-
import type { DocumentKeys, DocumentOutlet } from '../segment-lifetime/document-outlet.ts';
|
|
34
|
-
import type { SegmentLifetime } from '../types.ts';
|
|
35
|
-
|
|
36
|
-
/** One outlet in the element tree, and the outlets directly inside it. */
|
|
37
|
-
export interface OutletSpec {
|
|
38
|
-
segmentPath: string;
|
|
39
|
-
content: ReactNode;
|
|
40
|
-
nested: OutletSpec[];
|
|
41
|
-
/** Set on a `'document'` segment's outlet when the render can issue digests. */
|
|
42
|
-
document?: DocumentOutlet;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Per-request inputs to every gate in one render. */
|
|
46
|
-
export interface SegmentHashRender {
|
|
47
|
-
/** The hashes the client advertised (`X-Timber-State-Tree`), by path. */
|
|
48
|
-
clientHashes: ReadonlyMap<string, string> | null;
|
|
49
|
-
/** Hashes the outgoing stream; null when `clientSegmentCache` is off. */
|
|
50
|
-
tap: SegmentHashTap | null;
|
|
51
|
-
/**
|
|
52
|
-
* Bounds each capture's stream. A capture also ends with the main render
|
|
53
|
-
* (`tap.onEnd`), which usually comes first.
|
|
54
|
-
*/
|
|
55
|
-
captureTimeoutMs: number;
|
|
56
|
-
/**
|
|
57
|
-
* The main render's error handler. A capture is a segment's render, so its
|
|
58
|
-
* errors are the render's: reported, digested and signalled once, there.
|
|
59
|
-
*/
|
|
60
|
-
onCaptureError?: (error: unknown) => string | void;
|
|
61
|
-
signal?: AbortSignal;
|
|
62
|
-
/**
|
|
63
|
-
* Key digests for `'document'` segments: the client's, and the signer that
|
|
64
|
-
* issues and checks them. Null when no client router can hold a segment.
|
|
65
|
-
*/
|
|
66
|
-
documents: DocumentKeys | null;
|
|
67
|
-
/**
|
|
68
|
-
* The lifetime of a layout that declares none: the app's
|
|
69
|
-
* `defaultLayoutLifetime` (design/53 §"App-wide default"). Pages always
|
|
70
|
-
* default to `'request'`.
|
|
71
|
-
*/
|
|
72
|
-
defaultLayoutLifetime: SegmentLifetime;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** A render with dedupe off: every segment live, no hashes. */
|
|
76
|
-
export const NO_SEGMENT_HASHING: SegmentHashRender = {
|
|
77
|
-
clientHashes: null,
|
|
78
|
-
tap: null,
|
|
79
|
-
captureTimeoutMs: 0,
|
|
80
|
-
documents: null,
|
|
81
|
-
defaultLayoutLifetime: 'request',
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Whether a decoded element type is timber's `SegmentOutlet` client
|
|
86
|
-
* reference. Matched by reference id — module and export — so an app
|
|
87
|
-
* component that happened to be exported as `SegmentOutlet` is not read as a
|
|
88
|
-
* hole, which would keep changes inside it out of its segment's hash.
|
|
89
|
-
*/
|
|
90
|
-
export function isOutletType(type: unknown): boolean {
|
|
91
|
-
if (typeof type !== 'function' && (typeof type !== 'object' || type === null)) return false;
|
|
92
|
-
const id = (type as { $$id?: unknown }).$$id;
|
|
93
|
-
const outlet = (clientComponents().SegmentOutlet as { $$id?: unknown }).$$id;
|
|
94
|
-
return (
|
|
95
|
-
typeof id === 'string' &&
|
|
96
|
-
typeof outlet === 'string' &&
|
|
97
|
-
stripReferenceCacheTag(id) === stripReferenceCacheTag(outlet)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The element for an outlet: a server component that decides when it renders
|
|
103
|
-
* — after every access gate above it — and inside a capture renders a bare
|
|
104
|
-
* hole, since the nested segment's content belongs to its own hash.
|
|
105
|
-
*
|
|
106
|
-
* A closure with no props rather than a component taking `{ spec, render }`:
|
|
107
|
-
* dev Flight serializes a server component's props as debug info, and these
|
|
108
|
-
* would repeat the whole subtree in every dev payload.
|
|
109
|
-
*/
|
|
110
|
-
export function outletGate(spec: OutletSpec, render: SegmentHashRender): ReactElement {
|
|
111
|
-
function OutletGate(): ReactElement {
|
|
112
|
-
const { SegmentOutlet } = clientComponents();
|
|
113
|
-
const marker = captureHoleMarker(spec.segmentPath);
|
|
114
|
-
if (marker)
|
|
115
|
-
return createElement(SegmentOutlet, { segmentPath: spec.segmentPath, decision: marker });
|
|
116
|
-
return createElement(SegmentOutlet, {
|
|
117
|
-
segmentPath: spec.segmentPath,
|
|
118
|
-
decision: decide(spec, render),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
OUTLET_GATES.add(OutletGate);
|
|
122
|
-
return createElement(OutletGate);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Every gate component `outletGate` made, so a subtree walk can stop at one. */
|
|
126
|
-
const OUTLET_GATES = new WeakSet<object>();
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Whether `node` is an outlet gate element — the boundary of the segment
|
|
130
|
-
* whose content contains it. A walk over one segment's output (a
|
|
131
|
-
* 'document' segment's read scope) stops here: what renders inside belongs
|
|
132
|
-
* to the nested segment and its own rules.
|
|
133
|
-
*/
|
|
134
|
-
export function isOutletGateElement(node: unknown): boolean {
|
|
135
|
-
if (typeof node !== 'object' || node === null || !('type' in node)) return false;
|
|
136
|
-
const type = (node as { type: unknown }).type;
|
|
137
|
-
return typeof type === 'function' && OUTLET_GATES.has(type);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function decide(spec: OutletSpec, render: SegmentHashRender): OutletDecisionValue {
|
|
141
|
-
if (spec.document) {
|
|
142
|
-
if ('held' in spec.document) return documentSkip(spec, render, spec.document.held);
|
|
143
|
-
return { children: spec.content, digest: spec.document.issued };
|
|
144
|
-
}
|
|
145
|
-
const clientHash = render.clientHashes?.get(spec.segmentPath);
|
|
146
|
-
if (clientHash === undefined) return live(spec, render, spec.content);
|
|
147
|
-
// Development Flight follows this decision's async chain into the capture's
|
|
148
|
-
// reads, whose awaited values include the decoded segment. It writes those
|
|
149
|
-
// as debug rows only for awaits in app code; every render filters timber's
|
|
150
|
-
// own frames out (framework-stack-frames.ts), so a skip sends nothing.
|
|
151
|
-
return compare(spec, render, clientHash);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function compare(
|
|
155
|
-
spec: OutletSpec,
|
|
156
|
-
render: SegmentHashRender,
|
|
157
|
-
clientHash: string
|
|
158
|
-
): Promise<OutletDecision> {
|
|
159
|
-
return captureSegment(spec.content, {
|
|
160
|
-
segmentPath: spec.segmentPath,
|
|
161
|
-
timeoutMs: render.captureTimeoutMs,
|
|
162
|
-
signal: render.signal,
|
|
163
|
-
onRenderEnd: render.tap?.onEnd,
|
|
164
|
-
onError: render.onCaptureError,
|
|
165
|
-
isOutlet: isOutletType,
|
|
166
|
-
decideHole: (path) => decideNested(spec, path, render),
|
|
167
|
-
}).then(
|
|
168
|
-
(capture) => {
|
|
169
|
-
if (capture.kind === 'complete' && capture.hash === clientHash) {
|
|
170
|
-
capture.discard();
|
|
171
|
-
return skip(spec, render, capture);
|
|
172
|
-
}
|
|
173
|
-
// Sent live: the capture's own elements, decoded — not a second render.
|
|
174
|
-
return live(spec, render, capture.content);
|
|
175
|
-
},
|
|
176
|
-
// The capture could not be started at all (renderFlight threw before
|
|
177
|
-
// rendering anything): render the segment inline, as without a hash.
|
|
178
|
-
() => live(spec, render, spec.content)
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** The decision for the nested outlet at `path`, which rendered as a hole. */
|
|
183
|
-
function decideNested(
|
|
184
|
-
spec: OutletSpec,
|
|
185
|
-
path: string,
|
|
186
|
-
render: SegmentHashRender
|
|
187
|
-
): OutletDecisionValue | undefined {
|
|
188
|
-
const nested = spec.nested.find((n) => n.segmentPath === path);
|
|
189
|
-
// A hole the builder did not record under this segment cannot be decided;
|
|
190
|
-
// the client refuses an outlet without a decision rather than show it stale.
|
|
191
|
-
return nested ? decide(nested, render) : undefined;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function live(spec: OutletSpec, render: SegmentHashRender, children: ReactNode): OutletDecision {
|
|
195
|
-
if (!render.tap) return { children };
|
|
196
|
-
return { hash: render.tap.advertise(spec.segmentPath), children };
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* A skip decides exactly the nested outlets its capture rendered as holes —
|
|
201
|
-
* the ones whose access gates passed. Those are also exactly the outlets in
|
|
202
|
-
* the client's cached copy, since the hashes matched. A nested outlet whose
|
|
203
|
-
* gate denied is not decided at all: deciding it would render its content.
|
|
204
|
-
*/
|
|
205
|
-
function skip(
|
|
206
|
-
spec: OutletSpec,
|
|
207
|
-
render: SegmentHashRender,
|
|
208
|
-
capture: Extract<SegmentCapture, { kind: 'complete' }>
|
|
209
|
-
): OutletDecision {
|
|
210
|
-
const outlets: Record<string, OutletDecisionValue> = {};
|
|
211
|
-
for (const nested of spec.nested) {
|
|
212
|
-
if (capture.holes.has(nested.segmentPath)) outlets[nested.segmentPath] = decide(nested, render);
|
|
213
|
-
}
|
|
214
|
-
return { skip: true, hash: capture.hash, outlets };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* A `'document'` skip: the segment is not rendered, so nothing says which
|
|
219
|
-
* nested outlets its content would hold — every one is decided. The client
|
|
220
|
-
* renders only those in its cached copy; a nested segment a layout body hid
|
|
221
|
-
* at load is still rendered and serialized here (its own `access.ts` still
|
|
222
|
-
* gates it), which is why a `'document'` layout body is not a data-hiding
|
|
223
|
-
* boundary (design/53 §"What stays frozen").
|
|
224
|
-
*/
|
|
225
|
-
function documentSkip(spec: OutletSpec, render: SegmentHashRender, digest: string): OutletDecision {
|
|
226
|
-
const outlets: Record<string, OutletDecisionValue> = {};
|
|
227
|
-
for (const nested of spec.nested) outlets[nested.segmentPath] = decide(nested, render);
|
|
228
|
-
return { skip: true, digest, outlets };
|
|
229
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The advertised hash: each live segment's hash, computed from what the main
|
|
3
|
-
* Flight stream actually sent.
|
|
4
|
-
*
|
|
5
|
-
* A live `SegmentOutlet` carries `decision.hash` as a promise. The tap feeds
|
|
6
|
-
* the outgoing stream to React's own Flight client in the RSC environment,
|
|
7
|
-
* finds each live outlet in the decoded tree, and once everything the
|
|
8
|
-
* decision's `children` reach has settled, resolves that promise with the
|
|
9
|
-
* hash of those decoded values (value-hash.ts). Flight then writes the hash
|
|
10
|
-
* as one more row. The client stores it beside the content it committed, so
|
|
11
|
-
* the hash it later advertises describes exactly what it received
|
|
12
|
-
* (design/52 §"Two hashes, two jobs").
|
|
13
|
-
*
|
|
14
|
-
* Nothing about this can stall the response: a hash the tap cannot compute
|
|
15
|
-
* resolves to null once the decoded payload has been explored without
|
|
16
|
-
* finding its outlet, or when the stream ends, and every pending hash
|
|
17
|
-
* resolves to null once `timeoutMs` passes — a pending promise would otherwise hold the
|
|
18
|
-
* Flight stream open.
|
|
19
|
-
*
|
|
20
|
-
* See design/52-segment-hash-dedupe.md §"Wire format".
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { hashSettledValue } from './value-hash.ts';
|
|
24
|
-
|
|
25
|
-
export interface SegmentHashTap {
|
|
26
|
-
/**
|
|
27
|
-
* The hash of live segment `segmentPath`'s content in this stream, once it
|
|
28
|
-
* has all arrived. Null when it cannot be computed.
|
|
29
|
-
*/
|
|
30
|
-
advertise(segmentPath: string): Promise<string | null>;
|
|
31
|
-
/** Feed one chunk of the outgoing stream. */
|
|
32
|
-
observe(chunk: Uint8Array): void;
|
|
33
|
-
/** The stream ended or was cancelled: give up on everything pending. */
|
|
34
|
-
end(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Run `cancel` once the stream ends, however it ends; returns the
|
|
37
|
-
* unsubscribe. Captures started for this render stop with it (capture.ts) —
|
|
38
|
-
* nothing waits on them any more. A callback list rather than an
|
|
39
|
-
* AbortSignal: aborting a signal from the stream's teardown kept every
|
|
40
|
-
* finished request reachable in dev (tests/e2e/dev-request-retention.test.ts).
|
|
41
|
-
*/
|
|
42
|
-
onEnd(cancel: () => void): () => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface SegmentHashTapOptions {
|
|
46
|
-
timeoutMs: number;
|
|
47
|
-
/** Whether a decoded element type is timber's `SegmentOutlet`. */
|
|
48
|
-
isOutlet: (type: unknown) => boolean;
|
|
49
|
-
/** React's Flight client in the RSC environment. */
|
|
50
|
-
decode: (stream: ReadableStream<Uint8Array>) => PromiseLike<unknown>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const LAZY = Symbol.for('react.lazy');
|
|
54
|
-
const ELEMENT = new Set([Symbol.for('react.transitional.element'), Symbol.for('react.element')]);
|
|
55
|
-
|
|
56
|
-
function isThenable(value: unknown): value is PromiseLike<unknown> {
|
|
57
|
-
return (
|
|
58
|
-
typeof value === 'object' &&
|
|
59
|
-
value !== null &&
|
|
60
|
-
typeof (value as { then?: unknown }).then === 'function'
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Await a decoded promise; a rejection settles to undefined. */
|
|
65
|
-
async function settled(value: PromiseLike<unknown>): Promise<unknown> {
|
|
66
|
-
try {
|
|
67
|
-
return await value;
|
|
68
|
-
} catch {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function createSegmentHashTap(options: SegmentHashTapOptions): SegmentHashTap {
|
|
74
|
-
const pending = new Map<string, (hash: string | null) => void>();
|
|
75
|
-
const computed = new Map<string, Promise<string | null>>();
|
|
76
|
-
const ambiguous = new Set<string>();
|
|
77
|
-
const onEnd = new Set<() => void>();
|
|
78
|
-
const state = { aborted: false };
|
|
79
|
-
let explored = false;
|
|
80
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
81
|
-
let controller: ReadableStreamDefaultController<Uint8Array> | null = null;
|
|
82
|
-
|
|
83
|
-
const stream = new ReadableStream<Uint8Array>({
|
|
84
|
-
start(c) {
|
|
85
|
-
controller = c;
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
function settle(path: string, hash: string | null): void {
|
|
90
|
-
const resolve = pending.get(path);
|
|
91
|
-
if (!resolve) return;
|
|
92
|
-
pending.delete(path);
|
|
93
|
-
resolve(hash);
|
|
94
|
-
if (pending.size === 0 && timer !== undefined) {
|
|
95
|
-
clearTimeout(timer);
|
|
96
|
-
timer = undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function deliver(path: string): void {
|
|
101
|
-
const hash = computed.get(path);
|
|
102
|
-
if (!hash || !pending.has(path)) return;
|
|
103
|
-
// A hash that cannot be computed is no hash — never a rejection left to
|
|
104
|
-
// crash the process.
|
|
105
|
-
void hash.then(
|
|
106
|
-
(h) => settle(path, ambiguous.has(path) ? null : h),
|
|
107
|
-
() => settle(path, null)
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ─── Finding the outlets in the decoded tree ─────────────────────────────
|
|
112
|
-
|
|
113
|
-
const visited = new WeakSet<object>();
|
|
114
|
-
|
|
115
|
-
/** Walk a decoded value for outlet elements, waiting on what is pending. */
|
|
116
|
-
async function explore(value: unknown): Promise<void> {
|
|
117
|
-
if (state.aborted || value === null || typeof value !== 'object') return;
|
|
118
|
-
if (visited.has(value)) return;
|
|
119
|
-
visited.add(value);
|
|
120
|
-
const tagged = value as { $$typeof?: unknown; _payload?: unknown };
|
|
121
|
-
if (tagged.$$typeof === LAZY) {
|
|
122
|
-
if (isThenable(tagged._payload)) await explore(await settled(tagged._payload));
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (tagged.$$typeof !== undefined && ELEMENT.has(tagged.$$typeof as symbol)) {
|
|
126
|
-
const { props } = value as { props: Record<string, unknown> | null };
|
|
127
|
-
// A client component's type arrives as a lazy reference to its module.
|
|
128
|
-
let type = (value as { type: unknown }).type;
|
|
129
|
-
const lazyType = type as { $$typeof?: unknown; _payload?: unknown } | null;
|
|
130
|
-
if (lazyType && typeof lazyType === 'object' && lazyType.$$typeof === LAZY) {
|
|
131
|
-
type = isThenable(lazyType._payload) ? await settled(lazyType._payload) : undefined;
|
|
132
|
-
}
|
|
133
|
-
if (options.isOutlet(type) && props) {
|
|
134
|
-
await outlet(props.segmentPath, props.decision);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
await explore(props);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (isThenable(value)) {
|
|
141
|
-
await explore(await settled(value));
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const children: unknown[] = Array.isArray(value)
|
|
145
|
-
? value
|
|
146
|
-
: value instanceof Map
|
|
147
|
-
? [...value.keys(), ...value.values()]
|
|
148
|
-
: value instanceof Set
|
|
149
|
-
? [...value]
|
|
150
|
-
: Object.getPrototypeOf(value) === Object.prototype ||
|
|
151
|
-
Object.getPrototypeOf(value) === null
|
|
152
|
-
? Object.values(value)
|
|
153
|
-
: [];
|
|
154
|
-
await Promise.all(children.map(explore));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** One outlet: hash it if live, and find the outlets inside it. */
|
|
158
|
-
async function outlet(segmentPath: unknown, decisionValue: unknown): Promise<void> {
|
|
159
|
-
if (typeof segmentPath !== 'string') return;
|
|
160
|
-
const decision = isThenable(decisionValue) ? await settled(decisionValue) : decisionValue;
|
|
161
|
-
if (!decision || typeof decision !== 'object') return;
|
|
162
|
-
const d = decision as { skip?: unknown; children?: unknown; outlets?: unknown };
|
|
163
|
-
if (d.skip === true) {
|
|
164
|
-
// A skip carries its nested segments' decisions.
|
|
165
|
-
const outlets = d.outlets && typeof d.outlets === 'object' ? d.outlets : {};
|
|
166
|
-
await Promise.all(Object.entries(outlets).map(([path, nested]) => outlet(path, nested)));
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (computed.has(segmentPath)) ambiguous.add(segmentPath);
|
|
170
|
-
computed.set(segmentPath, hashSettledValue(d.children, { isOutlet: options.isOutlet }, state));
|
|
171
|
-
deliver(segmentPath);
|
|
172
|
-
await explore(d.children);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Everything the payload reaches has been explored: an outlet whose hash is
|
|
177
|
-
* still pending is one the walk did not find (a value kind it does not
|
|
178
|
-
* descend into). Its hash is none — it must not hold the stream open until
|
|
179
|
-
* the deadline.
|
|
180
|
-
*/
|
|
181
|
-
function exploredAll(): void {
|
|
182
|
-
explored = true;
|
|
183
|
-
for (const path of [...pending.keys()]) if (!computed.has(path)) settle(path, null);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Decoding starts at once and reads whatever `observe` feeds it. A decoder
|
|
187
|
-
// that throws — even synchronously — ends hashing, never the response.
|
|
188
|
-
void new Promise<unknown>((resolve) => resolve(options.decode(stream)))
|
|
189
|
-
.then((root) => explore(root))
|
|
190
|
-
.then(exploredAll)
|
|
191
|
-
.catch(() => end());
|
|
192
|
-
|
|
193
|
-
function end(): void {
|
|
194
|
-
if (state.aborted) return;
|
|
195
|
-
state.aborted = true;
|
|
196
|
-
for (const cancel of [...onEnd]) cancel();
|
|
197
|
-
onEnd.clear();
|
|
198
|
-
if (timer !== undefined) clearTimeout(timer);
|
|
199
|
-
timer = undefined;
|
|
200
|
-
try {
|
|
201
|
-
controller?.close();
|
|
202
|
-
} catch {
|
|
203
|
-
// Already closed or errored.
|
|
204
|
-
}
|
|
205
|
-
controller = null;
|
|
206
|
-
for (const path of [...pending.keys()]) settle(path, null);
|
|
207
|
-
computed.clear();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
advertise(segmentPath) {
|
|
212
|
-
if (state.aborted) return Promise.resolve(null);
|
|
213
|
-
if (pending.has(segmentPath)) {
|
|
214
|
-
// Two live outlets claimed one path: neither hash is trustworthy.
|
|
215
|
-
ambiguous.add(segmentPath);
|
|
216
|
-
settle(segmentPath, null);
|
|
217
|
-
return Promise.resolve(null);
|
|
218
|
-
}
|
|
219
|
-
if (explored && !computed.has(segmentPath)) return Promise.resolve(null);
|
|
220
|
-
const promise = new Promise<string | null>((resolve) => pending.set(segmentPath, resolve));
|
|
221
|
-
timer ??= setTimeout(end, options.timeoutMs);
|
|
222
|
-
deliver(segmentPath);
|
|
223
|
-
return promise;
|
|
224
|
-
},
|
|
225
|
-
observe(chunk) {
|
|
226
|
-
// The tap runs inside the response's stream: nothing it does may break
|
|
227
|
-
// that stream. A chunk it cannot hand on ends hashing for this response.
|
|
228
|
-
try {
|
|
229
|
-
controller?.enqueue(chunk);
|
|
230
|
-
} catch {
|
|
231
|
-
end();
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
end,
|
|
235
|
-
onEnd(cancel) {
|
|
236
|
-
if (state.aborted) {
|
|
237
|
-
cancel();
|
|
238
|
-
return () => {};
|
|
239
|
-
}
|
|
240
|
-
onEnd.add(cancel);
|
|
241
|
-
return () => onEnd.delete(cancel);
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
}
|