@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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outlet gate: renders one segment as a `SegmentOutlet` whose decision is
|
|
3
|
+
* either its live content or a skip.
|
|
4
|
+
*
|
|
5
|
+
* Only a `'document'` segment (design/53-segment-lifetime.md) is ever
|
|
6
|
+
* skipped. Its decision is made before the tree renders
|
|
7
|
+
* (`document-outlet.ts`): when the client holds content rendered under the
|
|
8
|
+
* current key digest, the segment is skipped **without rendering**, and its
|
|
9
|
+
* nested outlets are decided as if it had rendered — lifetime does not
|
|
10
|
+
* cascade. Otherwise it is sent live with the digest it rendered under. Every
|
|
11
|
+
* other segment is sent live. Access runs for every segment either way.
|
|
12
|
+
*
|
|
13
|
+
* See design/53-segment-lifetime.md §"Skipping".
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { createElement, type ReactElement, type ReactNode } from 'react';
|
|
17
|
+
import type { OutletDecision } from '../../shared/outlet-decision.ts';
|
|
18
|
+
import { clientComponents } from '../vite-handoff-rsc.ts';
|
|
19
|
+
import type { DocumentKeys, DocumentOutlet } from './document-outlet.ts';
|
|
20
|
+
import type { SegmentLifetime } from '../types.ts';
|
|
21
|
+
|
|
22
|
+
/** One outlet in the element tree, and the outlets directly inside it. */
|
|
23
|
+
export interface OutletSpec {
|
|
24
|
+
segmentPath: string;
|
|
25
|
+
content: ReactNode;
|
|
26
|
+
nested: OutletSpec[];
|
|
27
|
+
/** Set on a `'document'` segment's outlet when the render can issue digests. */
|
|
28
|
+
document?: DocumentOutlet;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Per-request inputs to every gate in one render. */
|
|
32
|
+
export interface SegmentRender {
|
|
33
|
+
/**
|
|
34
|
+
* Key digests for `'document'` segments: the client's, and the signer that
|
|
35
|
+
* issues and checks them. Null when no client router can hold a segment.
|
|
36
|
+
*/
|
|
37
|
+
documents: DocumentKeys | null;
|
|
38
|
+
/**
|
|
39
|
+
* The lifetime of a layout that declares none: the app's
|
|
40
|
+
* `defaultLayoutLifetime` (design/53 §"App-wide default"). Pages always
|
|
41
|
+
* default to `'request'`.
|
|
42
|
+
*/
|
|
43
|
+
defaultLayoutLifetime: SegmentLifetime;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A render with no client router to hold segments: every outlet live. */
|
|
47
|
+
export const LIVE_ONLY_RENDER: SegmentRender = {
|
|
48
|
+
documents: null,
|
|
49
|
+
defaultLayoutLifetime: 'request',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The element for an outlet: a server component that decides when it renders
|
|
54
|
+
* — after every access gate above it.
|
|
55
|
+
*
|
|
56
|
+
* A closure with no props rather than a component taking `{ spec }`:
|
|
57
|
+
* dev Flight serializes a server component's props as debug info, and these
|
|
58
|
+
* would repeat the whole subtree in every dev payload.
|
|
59
|
+
*/
|
|
60
|
+
export function outletGate(spec: OutletSpec): ReactElement {
|
|
61
|
+
function OutletGate(): ReactElement {
|
|
62
|
+
const { SegmentOutlet } = clientComponents();
|
|
63
|
+
return createElement(SegmentOutlet, { segmentPath: spec.segmentPath, decision: decide(spec) });
|
|
64
|
+
}
|
|
65
|
+
OUTLET_GATES.add(OutletGate);
|
|
66
|
+
return createElement(OutletGate);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Every gate component `outletGate` made, so a subtree walk can stop at one. */
|
|
70
|
+
const OUTLET_GATES = new WeakSet<object>();
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whether `node` is an outlet gate element — the boundary of the segment
|
|
74
|
+
* whose content contains it. A walk over one segment's output (a
|
|
75
|
+
* 'document' segment's read scope) stops here: what renders inside belongs
|
|
76
|
+
* to the nested segment and its own rules.
|
|
77
|
+
*/
|
|
78
|
+
export function isOutletGateElement(node: unknown): boolean {
|
|
79
|
+
if (typeof node !== 'object' || node === null || !('type' in node)) return false;
|
|
80
|
+
const type = (node as { type: unknown }).type;
|
|
81
|
+
return typeof type === 'function' && OUTLET_GATES.has(type);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function decide(spec: OutletSpec): OutletDecision {
|
|
85
|
+
if (!spec.document) return { children: spec.content };
|
|
86
|
+
if ('issued' in spec.document) return { children: spec.content, digest: spec.document.issued };
|
|
87
|
+
return documentSkip(spec, spec.document.held);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A `'document'` skip: the segment is not rendered, so nothing says which
|
|
92
|
+
* nested outlets its content would hold — every one is decided. The client
|
|
93
|
+
* renders only those in its cached copy; a nested segment a layout body hid
|
|
94
|
+
* at load is still rendered and serialized here (its own `access.ts` still
|
|
95
|
+
* gates it), which is why a `'document'` layout body is not a data-hiding
|
|
96
|
+
* boundary (design/53 §"What stays frozen").
|
|
97
|
+
*/
|
|
98
|
+
function documentSkip(spec: OutletSpec, digest: string): OutletDecision {
|
|
99
|
+
const outlets: Record<string, OutletDecision> = {};
|
|
100
|
+
for (const nested of spec.nested) outlets[nested.segmentPath] = decide(nested);
|
|
101
|
+
return { skip: true, digest, outlets };
|
|
102
|
+
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import { documentReadScopeAls, type DocumentReadScope } from '../als-registry.ts';
|
|
9
9
|
import type { CoercedParams } from '../../shared/param-value.ts';
|
|
10
10
|
import type { SearchParamsReader } from '../../shared/als-slots.ts';
|
|
11
|
+
import type { ReadonlyHeaders } from '../request-context.ts';
|
|
12
|
+
import { isUnkeyableHeader } from '../../shared/key-headers.ts';
|
|
11
13
|
|
|
12
14
|
/** The read scope the current render runs in, if it is a `'document'` segment's. */
|
|
13
15
|
export function currentReadScope(): DocumentReadScope | undefined {
|
|
@@ -15,16 +17,24 @@ export function currentReadScope(): DocumentReadScope | undefined {
|
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/** Which part of a key would allow a read, for the error's fix. */
|
|
18
|
-
type KeyPart = 'segmentParams' | 'searchParams' | 'cookies';
|
|
20
|
+
type KeyPart = 'segmentParams' | 'searchParams' | 'cookies' | 'headers';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* The error for a read outside the key. Names the segment, what was read, and
|
|
22
24
|
* the fix: add it to the key, or make the segment `'request'`.
|
|
23
25
|
*/
|
|
24
|
-
export function readOutsideKey(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
export function readOutsideKey(
|
|
27
|
+
scope: DocumentReadScope,
|
|
28
|
+
what: string,
|
|
29
|
+
part?: KeyPart,
|
|
30
|
+
/** Overrides the fix when adding the read to the key is not possible. */
|
|
31
|
+
fixOverride?: string
|
|
32
|
+
): Error {
|
|
33
|
+
const fix =
|
|
34
|
+
fixOverride ??
|
|
35
|
+
(part
|
|
36
|
+
? `Add it to key.${part}, or declare lifetime: 'request'.`
|
|
37
|
+
: "A 'document' segment cannot depend on it; declare lifetime: 'request'.");
|
|
28
38
|
return new Error(
|
|
29
39
|
`[timber] ${scope.segmentPath} is lifetime: 'document' (declared, or from defaultLayoutLifetime) ` +
|
|
30
40
|
`and read ${what}, which is not in its key. ` +
|
|
@@ -34,7 +44,54 @@ export function readOutsideKey(scope: DocumentReadScope, what: string, part?: Ke
|
|
|
34
44
|
);
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* The request headers as a `'document'` segment may read them: `get` and
|
|
49
|
+
* `has` of a header in its key. Any other name throws, and so does reading
|
|
50
|
+
* them all (iteration, `entries`, `forEach`), which could see headers the
|
|
51
|
+
* key leaves out — the pathname among them.
|
|
52
|
+
*/
|
|
53
|
+
export function keyedHeaders(headers: ReadonlyHeaders, scope: DocumentReadScope): ReadonlyHeaders {
|
|
54
|
+
const keyed = (name: string): string => {
|
|
55
|
+
if (scope.headers.has(name.toLowerCase())) return name;
|
|
56
|
+
const what = `the header "${name}"`;
|
|
57
|
+
if (name.toLowerCase() === 'cookie') {
|
|
58
|
+
throw readOutsideKey(
|
|
59
|
+
scope,
|
|
60
|
+
what,
|
|
61
|
+
'cookies',
|
|
62
|
+
'Read cookies through a cookie definition in key.cookies.'
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (isUnkeyableHeader(name)) {
|
|
66
|
+
throw readOutsideKey(
|
|
67
|
+
scope,
|
|
68
|
+
what,
|
|
69
|
+
undefined,
|
|
70
|
+
"A key may not name a credential; declare lifetime: 'request'."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
throw readOutsideKey(scope, what, 'headers');
|
|
74
|
+
};
|
|
75
|
+
const all = (): never => {
|
|
76
|
+
throw readOutsideKey(
|
|
77
|
+
scope,
|
|
78
|
+
'every request header',
|
|
79
|
+
undefined,
|
|
80
|
+
"Read each header you need with getHeaders().get(name) and add it to key.headers, or declare lifetime: 'request'."
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
get: (name) => headers.get(keyed(name)),
|
|
85
|
+
has: (name) => headers.has(keyed(name)),
|
|
86
|
+
entries: all,
|
|
87
|
+
keys: all,
|
|
88
|
+
values: all,
|
|
89
|
+
forEach: all,
|
|
90
|
+
[Symbol.iterator]: all,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Throw if the current render may not read `what` at all (raw search params). */
|
|
38
95
|
export function assertUnscopedRead(what: string): void {
|
|
39
96
|
const scope = currentReadScope();
|
|
40
97
|
if (scope) throw readOutsideKey(scope, what);
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* - a search-params definition's `.get()` throws unless every field it reads is
|
|
12
12
|
* in the key's definition, and the raw search params throw;
|
|
13
13
|
* - the cookie jar throws on a cookie outside the key, and on `getAll()`;
|
|
14
|
-
* - the
|
|
14
|
+
* - `getHeaders()` reads only the headers in the key; any other header, and
|
|
15
|
+
* iterating them all, throws — and with that the pathname, which no timber
|
|
15
16
|
* API exposes to a component except through a header.
|
|
16
17
|
*
|
|
17
18
|
* **Reach.** The scope is an AsyncLocalStorage scope around the segment's
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
import { createElement, type ReactNode } from 'react';
|
|
31
32
|
|
|
32
33
|
import { documentReadScopeAls, type DocumentReadScope } from '../als-registry.ts';
|
|
33
|
-
import { isOutletGateElement } from '
|
|
34
|
+
import { isOutletGateElement } from './outlet-gate.ts';
|
|
34
35
|
import { callAndRewrite, type ServerComponent, type SubtreeRule } from '../subtree-walk.ts';
|
|
35
36
|
import type { DocumentLifetime } from './segment-key.ts';
|
|
36
37
|
|
|
@@ -51,6 +52,7 @@ export function readScopeFor(
|
|
|
51
52
|
])
|
|
52
53
|
),
|
|
53
54
|
cookies: new Map((key.cookies ?? []).map((cookie) => [cookie.name, cookie.codec])),
|
|
55
|
+
headers: new Set((key.headers ?? []).map((name) => name.toLowerCase())),
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* - **segment params** — the coerced params (each segment's codec applied);
|
|
13
13
|
* - **search params** — `def.buildSearchParams(def.parse(…))`, which applies
|
|
14
14
|
* defaults, aliases (`withUrlKey`) and drops values that parse to the default;
|
|
15
|
+
* - **headers** — each named header's value as `Headers.get` returns it
|
|
16
|
+
* (trimmed, repeats joined with ", "), or null when absent, by lowercased
|
|
17
|
+
* name; headers have no codec, so equivalent spellings differ;
|
|
15
18
|
* - **cookies** — `codec.serialize(codec.parse(raw))` per definition. The raw
|
|
16
19
|
* value comes from the request's cookie jar, which reflects cookies the
|
|
17
20
|
* current server action set (design/53 open question 4), so an action's
|
|
@@ -22,7 +25,8 @@
|
|
|
22
25
|
import type { CoercedParams } from '../../shared/param-value.ts';
|
|
23
26
|
import { ROUTE_OPTIONS_EXPORT, type RouteOptionsKind } from '../../shared/route-options-export.ts';
|
|
24
27
|
import { getCookieJar } from '../cookie-context.ts';
|
|
25
|
-
import { getSearchParams } from '../request-context.ts';
|
|
28
|
+
import { getHeaders, getSearchParams } from '../request-context.ts';
|
|
29
|
+
import { headerKeyProblem } from '../../shared/key-headers.ts';
|
|
26
30
|
import type { SegmentKey, SegmentLifetime } from '../types.ts';
|
|
27
31
|
|
|
28
32
|
/** A segment declared `lifetime: 'document'`, with the key it declared (if any). */
|
|
@@ -69,7 +73,25 @@ export function readDocumentLifetime(
|
|
|
69
73
|
const key = 'key' in options ? options.key : undefined;
|
|
70
74
|
// The module's own export, typed `satisfies LayoutOptions` / `PageOptions`
|
|
71
75
|
// in source and shape-checked by the build; at runtime it is an `object`.
|
|
72
|
-
|
|
76
|
+
const segmentKey = typeof key === 'object' && key !== null ? (key as SegmentKey) : {};
|
|
77
|
+
assertKeyableHeaders(segmentKey.headers);
|
|
78
|
+
return { key: segmentKey };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Refuse a header the key may not name, at runtime too: the build does not
|
|
83
|
+
* read every file kind (an MDX page's options go unlinted), and a credential
|
|
84
|
+
* must not become keyable — and readable — by skipping the lint.
|
|
85
|
+
*/
|
|
86
|
+
function assertKeyableHeaders(headers: unknown): void {
|
|
87
|
+
if (headers === undefined) return;
|
|
88
|
+
if (!Array.isArray(headers) || !headers.every((h) => typeof h === 'string')) {
|
|
89
|
+
throw new Error('[timber] key.headers must be an array of header names.');
|
|
90
|
+
}
|
|
91
|
+
for (const name of headers) {
|
|
92
|
+
const problem = headerKeyProblem(name);
|
|
93
|
+
if (problem) throw new Error(`[timber] ${problem}`);
|
|
94
|
+
}
|
|
73
95
|
}
|
|
74
96
|
|
|
75
97
|
/**
|
|
@@ -99,7 +121,13 @@ export function readKeyValues(
|
|
|
99
121
|
cookie.codec.serialize(cookie.codec.parse(jar?.get(cookie.name))),
|
|
100
122
|
]);
|
|
101
123
|
|
|
102
|
-
|
|
124
|
+
const requestHeaders = key.headers && key.headers.length > 0 ? getHeaders() : null;
|
|
125
|
+
const headers = (key.headers ?? []).map((name) => [
|
|
126
|
+
name.toLowerCase(),
|
|
127
|
+
requestHeaders?.get(name) ?? null,
|
|
128
|
+
]);
|
|
129
|
+
|
|
130
|
+
return JSON.stringify([segmentParams, searchParams, cookies, headers]);
|
|
103
131
|
}
|
|
104
132
|
|
|
105
133
|
/**
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
} from '../../routing/segment-keys.ts';
|
|
30
30
|
import type { CoercedParams } from '../../shared/param-value.ts';
|
|
31
31
|
import type { ManifestSegmentNode } from '../route-matcher.ts';
|
|
32
|
-
import { outletGate, type OutletSpec, type
|
|
32
|
+
import { outletGate, type OutletSpec, type SegmentRender } from './outlet-gate.ts';
|
|
33
33
|
import { documentOutletFor } from './document-outlet.ts';
|
|
34
34
|
import {
|
|
35
35
|
defaultLayoutLifetimeAt,
|
|
@@ -41,7 +41,7 @@ import type { ServerComponent } from '../subtree-walk.ts';
|
|
|
41
41
|
|
|
42
42
|
/** Everything a slot's `'document'` outlets need from the slot being resolved. */
|
|
43
43
|
export interface SlotDocumentContext {
|
|
44
|
-
render:
|
|
44
|
+
render: SegmentRender;
|
|
45
45
|
/** The slot's matched chain, slot root first. */
|
|
46
46
|
chain: readonly ManifestSegmentNode[];
|
|
47
47
|
/** The tree path of the segment that owns the slot. */
|
|
@@ -102,7 +102,7 @@ export class SlotDocumentOutlets {
|
|
|
102
102
|
document: await this.decision(node, segmentPath, lifetime),
|
|
103
103
|
};
|
|
104
104
|
this.unclaimed = [spec];
|
|
105
|
-
return outletGate(spec
|
|
105
|
+
return outletGate(spec);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
@@ -123,12 +123,12 @@ export class SlotDocumentOutlets {
|
|
|
123
123
|
};
|
|
124
124
|
const spec: OutletSpec = {
|
|
125
125
|
segmentPath,
|
|
126
|
-
content: buildLayout(outletGate(childrenOutlet
|
|
126
|
+
content: buildLayout(outletGate(childrenOutlet)),
|
|
127
127
|
nested: [childrenOutlet],
|
|
128
128
|
document: await this.decision(node, segmentPath, lifetime),
|
|
129
129
|
};
|
|
130
130
|
this.unclaimed = [spec];
|
|
131
|
-
return outletGate(spec
|
|
131
|
+
return outletGate(spec);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
@@ -34,11 +34,11 @@ import { extractUrlParts } from './chain-url-parts.ts';
|
|
|
34
34
|
import { findInterceptingMatch } from './slot-interception.ts';
|
|
35
35
|
import { computeSlotKey, slotChainTreePath } from '../routing/segment-keys.ts';
|
|
36
36
|
import {
|
|
37
|
-
|
|
37
|
+
LIVE_ONLY_RENDER,
|
|
38
38
|
outletGate,
|
|
39
39
|
type OutletSpec,
|
|
40
|
-
type
|
|
41
|
-
} from './segment-
|
|
40
|
+
type SegmentRender,
|
|
41
|
+
} from './segment-lifetime/outlet-gate.ts';
|
|
42
42
|
import { getSegmentParams } from './request-context.ts';
|
|
43
43
|
import { pathParamNames } from './segment-lifetime/document-outlet.ts';
|
|
44
44
|
import { SlotDocumentOutlets } from './segment-lifetime/slot-outlets.ts';
|
|
@@ -97,7 +97,7 @@ export async function resolveSlotElement(
|
|
|
97
97
|
req: Request,
|
|
98
98
|
interception?: InterceptionContext,
|
|
99
99
|
parentTreePath?: string,
|
|
100
|
-
render:
|
|
100
|
+
render: SegmentRender = LIVE_ONLY_RENDER
|
|
101
101
|
): Promise<ResolvedSlotElement> {
|
|
102
102
|
// When interception is active, try to match intercepting children in this
|
|
103
103
|
// slot against the target pathname. If an intercepting child matches, render
|
|
@@ -584,7 +584,7 @@ interface ResolveSlotPropsArgs {
|
|
|
584
584
|
parentTreePath: string;
|
|
585
585
|
/** The request being rendered. */
|
|
586
586
|
req: Request;
|
|
587
|
-
render:
|
|
587
|
+
render: SegmentRender;
|
|
588
588
|
}
|
|
589
589
|
|
|
590
590
|
/** A layout's slot props, and the outlet of each slot. */
|
|
@@ -597,8 +597,8 @@ export interface ResolvedSlots {
|
|
|
597
597
|
* Resolve all parallel route slots for a layout, each in its own outlet.
|
|
598
598
|
*
|
|
599
599
|
* Every slot is resolved and every slot's access chain runs, on every render.
|
|
600
|
-
*
|
|
601
|
-
*
|
|
600
|
+
* A slot is skipped only through the 'document' segments on its chain
|
|
601
|
+
* (design/53-segment-lifetime.md §"Slots").
|
|
602
602
|
*/
|
|
603
603
|
export async function resolveSlotProps({
|
|
604
604
|
segment,
|
|
@@ -629,7 +629,7 @@ export async function resolveSlotProps({
|
|
|
629
629
|
nested,
|
|
630
630
|
};
|
|
631
631
|
outlets.push(spec);
|
|
632
|
-
props[slotName] = outletGate(spec
|
|
632
|
+
props[slotName] = outletGate(spec);
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
return { props, outlets };
|
package/src/server/types.ts
CHANGED
|
@@ -107,8 +107,8 @@ export type SegmentLifetime = 'request' | 'document';
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* The request inputs a `'document'` segment depends on — and the only ones it
|
|
110
|
-
* may read.
|
|
111
|
-
* codec. See design/53-segment-lifetime.md §"Segment keys".
|
|
110
|
+
* may read. Params, search params and cookies are compared after parsing,
|
|
111
|
+
* through each definition's codec; headers as `Headers.get` returns them. See design/53-segment-lifetime.md §"Segment keys".
|
|
112
112
|
*/
|
|
113
113
|
export interface SegmentKey {
|
|
114
114
|
/**
|
|
@@ -120,6 +120,12 @@ export interface SegmentKey {
|
|
|
120
120
|
searchParams?: SearchParamsDefinition<Record<string, unknown>>;
|
|
121
121
|
/** Cookie definitions (`defineCookie`). Default: none. */
|
|
122
122
|
cookies?: readonly ServerOnlyCookieDefinition<unknown>[];
|
|
123
|
+
/**
|
|
124
|
+
* Request header names, matched case-insensitively; values compared as
|
|
125
|
+
* `Headers.get` returns them (trimmed, repeats joined). Default: none. `cookie` (use `cookies`) and credential headers
|
|
126
|
+
* (`authorization`, `proxy-authorization`, `x-api-key`) fail the build.
|
|
127
|
+
*/
|
|
128
|
+
headers?: readonly string[];
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
/** Options for a `page.tsx`: `export const pageOptions = { … } satisfies PageOptions`. */
|
|
@@ -38,24 +38,13 @@ import type { DenyLastResort } from '../client/deny-last-resort.tsx';
|
|
|
38
38
|
* decoder; the runtime only ever passes a stream and inspects the result, and
|
|
39
39
|
* the narrower type is what a test double can satisfy.
|
|
40
40
|
*/
|
|
41
|
-
/**
|
|
42
|
-
* The decode half of Flight's temporary references: each `$T<id>` in the
|
|
43
|
-
* stream is replaced by `get('$' + id)`. React's client reads only `get`.
|
|
44
|
-
*/
|
|
45
|
-
export interface TemporaryReferenceLookup {
|
|
46
|
-
get(key: string): unknown;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
41
|
export interface RscFlightRuntime {
|
|
50
42
|
renderFlight: typeof FlightAdapter.renderFlight;
|
|
51
43
|
loadServerAction: typeof FlightAdapter.loadServerAction;
|
|
52
44
|
decodeReply: typeof FlightAdapter.decodeReply;
|
|
53
45
|
decodeAction: typeof FlightAdapter.decodeAction;
|
|
54
46
|
decodeFormState: typeof FlightAdapter.decodeFormState;
|
|
55
|
-
createFromReadableStream: (
|
|
56
|
-
stream: ReadableStream<Uint8Array>,
|
|
57
|
-
options?: { temporaryReferences?: TemporaryReferenceLookup }
|
|
58
|
-
) => Promise<unknown>;
|
|
47
|
+
createFromReadableStream: (stream: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
59
48
|
}
|
|
60
49
|
|
|
61
50
|
/**
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which request headers a `'document'` segment's key may name
|
|
3
|
+
* (design/53-segment-lifetime.md §"Segment keys"). One rule for the build
|
|
4
|
+
* (`routing/route-options.ts`), which reports it from source, and for the
|
|
5
|
+
* runtime (`server/segment-lifetime/segment-key.ts`), which refuses it too —
|
|
6
|
+
* the build cannot read every file kind (MDX pages are not linted), and a
|
|
7
|
+
* credential must not become keyable by skipping the lint.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** RFC 9110 §5.6.2 `token`: what a header field name may be. */
|
|
11
|
+
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Headers a key may not name. `cookie` is read through cookie definitions
|
|
15
|
+
* (`key.cookies`). Credentials are secret, and a key answers guesses about
|
|
16
|
+
* its values to whoever holds a digest (design/53 §"The key digest").
|
|
17
|
+
*/
|
|
18
|
+
const CREDENTIAL = 'It carries a credential, and a key must not hold secret values.';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A `Map`, not an object literal: a header may be named `constructor` or
|
|
22
|
+
* `__proto__`, and an index lookup would find `Object.prototype`'s.
|
|
23
|
+
*/
|
|
24
|
+
const UNKEYABLE_HEADERS: ReadonlyMap<string, string> = new Map([
|
|
25
|
+
['cookie', 'Key on cookie definitions with key.cookies instead.'],
|
|
26
|
+
['authorization', CREDENTIAL],
|
|
27
|
+
['proxy-authorization', CREDENTIAL],
|
|
28
|
+
['x-api-key', CREDENTIAL],
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
/** Why a key may not name `name`, or undefined when it may. */
|
|
32
|
+
export function headerKeyProblem(name: string): string | undefined {
|
|
33
|
+
if (!HEADER_NAME.test(name))
|
|
34
|
+
return `key.headers names "${name}", which is not a valid header name.`;
|
|
35
|
+
const refused = UNKEYABLE_HEADERS.get(name.toLowerCase());
|
|
36
|
+
return refused ? `key.headers may not name "${name}". ${refused}` : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Whether a key may never name `name` (case-insensitive): a cookie or credential header. */
|
|
40
|
+
export function isUnkeyableHeader(name: string): boolean {
|
|
41
|
+
return UNKEYABLE_HEADERS.has(name.toLowerCase());
|
|
42
|
+
}
|
|
@@ -1,75 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What the server decided for one `SegmentOutlet` — the wire contract
|
|
3
|
-
* between the outlet gate (server/segment-
|
|
4
|
-
* outlet (client/segment-outlet.tsx).
|
|
3
|
+
* between the outlet gate (server/segment-lifetime/outlet-gate.ts) and the
|
|
4
|
+
* client outlet (client/segment-outlet.tsx).
|
|
5
5
|
*
|
|
6
6
|
* A segment is either sent or skipped:
|
|
7
7
|
*
|
|
8
|
-
* - **Live** — `children` is the segment's content. `
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* the
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - **Skip** — the client already holds content with this `hash`, and the
|
|
17
|
-
* server just produced identical output; or, for a `'document'` segment,
|
|
18
|
-
* the client holds content rendered under this `digest` and the request's
|
|
19
|
-
* key values still match it, so the server did not render the segment at
|
|
20
|
-
* all. `outlets` carries the decisions for the segments nested directly
|
|
21
|
-
* inside it, because the client renders its cached copy of this segment
|
|
22
|
-
* and that copy still holds the old ones.
|
|
8
|
+
* - **Live** — `children` is the segment's content. A `'document'` segment
|
|
9
|
+
* (design/53-segment-lifetime.md) also carries `digest`: the key digest it
|
|
10
|
+
* rendered under.
|
|
11
|
+
* - **Skip** — only a `'document'` segment: the client holds content rendered
|
|
12
|
+
* under this `digest` and the request's key values still match it, so the
|
|
13
|
+
* server did not render the segment at all. `outlets` carries the decisions
|
|
14
|
+
* for the segments nested directly inside it, because the client renders
|
|
15
|
+
* its cached copy of this segment and that copy still holds the old ones.
|
|
23
16
|
*
|
|
24
|
-
*
|
|
25
|
-
* render the segment once before deciding, and as a plain value otherwise.
|
|
26
|
-
*
|
|
27
|
-
* See design/52-segment-hash-dedupe.md §"Wire format".
|
|
17
|
+
* See design/53-segment-lifetime.md §"Skipping".
|
|
28
18
|
*/
|
|
29
19
|
|
|
30
20
|
import type { ReactNode } from 'react';
|
|
31
21
|
|
|
32
|
-
export type OutletDecision = LiveDecision |
|
|
22
|
+
export type OutletDecision = LiveDecision | DocumentSkip;
|
|
33
23
|
|
|
34
24
|
export interface LiveDecision {
|
|
35
25
|
skip?: undefined;
|
|
36
|
-
hash?: PromiseLike<string | null>;
|
|
37
26
|
/** The key digest of a `'document'` segment's content. */
|
|
38
27
|
digest?: string;
|
|
39
28
|
children: ReactNode;
|
|
40
29
|
}
|
|
41
30
|
|
|
42
|
-
export type SkipDecision = HashSkip | DocumentSkip;
|
|
43
|
-
|
|
44
|
-
/** A segment the server rendered and found identical to what the client holds. */
|
|
45
|
-
export interface HashSkip {
|
|
46
|
-
skip: true;
|
|
47
|
-
hash: string;
|
|
48
|
-
digest?: undefined;
|
|
49
|
-
/** The decisions of the segments nested directly inside, by segment path. */
|
|
50
|
-
outlets: Record<string, OutletDecisionValue>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
31
|
/** A `'document'` segment whose key is unchanged: never rendered. */
|
|
54
32
|
export interface DocumentSkip {
|
|
55
33
|
skip: true;
|
|
56
|
-
hash?: undefined;
|
|
57
34
|
digest: string;
|
|
58
35
|
/** The decisions of the segments nested directly inside, by segment path. */
|
|
59
|
-
outlets: Record<string,
|
|
36
|
+
outlets: Record<string, OutletDecision>;
|
|
60
37
|
}
|
|
61
38
|
|
|
62
|
-
/**
|
|
63
|
-
* What a nested outlet carries inside a segment-hash capture, in place of a
|
|
64
|
-
* decision: an opaque marker Flight writes as a temporary reference and the
|
|
65
|
-
* capture's decoder replaces with the real decision. Never reaches a client.
|
|
66
|
-
*/
|
|
67
|
-
export interface CaptureHole {
|
|
68
|
-
readonly captureHole: true;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** A decision as an outlet receives it. */
|
|
72
|
-
export type OutletDecisionValue = OutletDecision | PromiseLike<OutletDecision>;
|
|
73
|
-
|
|
74
39
|
/** The `segmentPath` of the metadata outlet — one per payload. */
|
|
75
40
|
export const METADATA_OUTLET_PATH = '#metadata';
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* 1. **A provider inside the payload cannot reach a skipped segment.** A
|
|
13
13
|
* segment the server skipped renders the content the client cached for it
|
|
14
|
-
* (design/
|
|
14
|
+
* (design/53-segment-lifetime.md), and that copy carries whatever was
|
|
15
15
|
* inside it when it was committed — never the incoming route's provider.
|
|
16
16
|
* Params belong to the *navigation*, so the provider has to be owned by the
|
|
17
17
|
* client, above the payload root, and there must be exactly one.
|
|
@@ -35,10 +35,8 @@ export interface SegmentInfo {
|
|
|
35
35
|
/**
|
|
36
36
|
* The client's `X-Timber-State-Tree` request header.
|
|
37
37
|
*
|
|
38
|
-
* `
|
|
39
|
-
*
|
|
40
|
-
* `clientSegmentCache` (design/52-segment-hash-dedupe.md). `treePaths` is
|
|
41
|
-
* not caching: it describes the *shape* of the tree currently on screen, so
|
|
38
|
+
* `documents` are the key digests of the `'document'` segments the client
|
|
39
|
+
* holds. `treePaths` is not caching: it describes the *shape* of the tree currently on screen, so
|
|
42
40
|
* the server can answer "does the rendered route pass through the segment
|
|
43
41
|
* that owns this intercepting slot?" without re-deriving it from the address
|
|
44
42
|
* bar, which stops being the source route the moment a modal is open
|
|
@@ -47,11 +45,9 @@ export interface SegmentInfo {
|
|
|
47
45
|
* Neither is a security input. Every `access.ts` runs regardless.
|
|
48
46
|
*/
|
|
49
47
|
export interface StateTree {
|
|
50
|
-
hashes?: Record<string, string>;
|
|
51
48
|
/**
|
|
52
49
|
* The key digests of the `'document'` segments the client holds, by outlet
|
|
53
|
-
* path (design/53-segment-lifetime.md).
|
|
54
|
-
* not; left out of the `_rsc` cache key.
|
|
50
|
+
* path (design/53-segment-lifetime.md). Left out of the `_rsc` cache key.
|
|
55
51
|
*/
|
|
56
52
|
documents?: Record<string, string>;
|
|
57
53
|
treePaths?: string[];
|