@timber-js/app 0.2.0-alpha.242 → 0.2.0-alpha.244
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-BkwgRwCl.js → actions-D_LiN5xG.js} +57 -39
- package/dist/_chunks/actions-D_LiN5xG.js.map +1 -0
- package/dist/_chunks/als-registry-C-iwbtvI.js.map +1 -1
- package/dist/_chunks/{cache-api-BGA7c5qJ.js → cache-api-D3HmgsFh.js} +4 -4
- package/dist/_chunks/{cache-api-BGA7c5qJ.js.map → cache-api-D3HmgsFh.js.map} +1 -1
- package/dist/_chunks/{chains-Cuwwjv6T.js → chains-BpvDwp08.js} +2 -2
- package/dist/_chunks/{chains-Cuwwjv6T.js.map → chains-BpvDwp08.js.map} +1 -1
- package/dist/_chunks/chains-CjlZZ5ad.js +1 -0
- package/dist/_chunks/{classify-Y8S9C0Na.js → classify-Bbb_lKjH.js} +2 -2
- package/dist/_chunks/{classify-Y8S9C0Na.js.map → classify-Bbb_lKjH.js.map} +1 -1
- package/dist/_chunks/{cli-check-KeE1QaIx.js → cli-check-BE9BnXwi.js} +6 -6
- package/dist/_chunks/cli-check-BE9BnXwi.js.map +1 -0
- package/dist/_chunks/{cli-schema-sync-DZEF31wd.js → cli-schema-sync-CWkGFlYu.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-DZEF31wd.js.map → cli-schema-sync-CWkGFlYu.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-_y5O6MIg.js → cli-schema-sync-Dyvdkv_I.js} +1 -1
- package/dist/_chunks/{client-dep-entries-DpiwvoDi.js → client-dep-entries-Dka67elj.js} +2 -2
- package/dist/_chunks/{client-dep-entries-DpiwvoDi.js.map → client-dep-entries-Dka67elj.js.map} +1 -1
- package/dist/_chunks/{convention-lint-0AEsPK2T.js → convention-lint-DkSDlsPH.js} +38 -10
- package/dist/_chunks/convention-lint-DkSDlsPH.js.map +1 -0
- package/dist/_chunks/{dev-server-DYDr8KIc.js → dev-server-BZxFJNih.js} +68 -11
- package/dist/_chunks/{dev-server-DYDr8KIc.js.map → dev-server-BZxFJNih.js.map} +1 -1
- package/dist/_chunks/dev-server-C72bB9Kg.js +1 -0
- package/dist/_chunks/error-boundary-wuNvAJ4n.js.map +1 -1
- package/dist/_chunks/{flight-source-node-KQsX_OhS.js → flight-source-node-BeF00Wo_.js} +2 -2
- package/dist/_chunks/{flight-source-node-KQsX_OhS.js.map → flight-source-node-BeF00Wo_.js.map} +1 -1
- package/dist/_chunks/{interception-CtNt9jPt.js → interception-D1dCGNmQ.js} +6 -6
- package/dist/_chunks/{interception-CtNt9jPt.js.map → interception-D1dCGNmQ.js.map} +1 -1
- package/dist/_chunks/{json-lossy-check-BVDALqMf.js → json-lossy-check-DpXneTBm.js} +2 -2
- package/dist/_chunks/{json-lossy-check-BVDALqMf.js.map → json-lossy-check-DpXneTBm.js.map} +1 -1
- package/dist/_chunks/{key-headers-uIig1_mU.js → key-headers-CVpa6fpW.js} +6 -2
- package/dist/_chunks/key-headers-CVpa6fpW.js.map +1 -0
- package/dist/_chunks/{live-graph-VhzO7Ol9.js → live-graph-DXhz6A_X.js} +4 -4
- package/dist/_chunks/{live-graph-VhzO7Ol9.js.map → live-graph-DXhz6A_X.js.map} +1 -1
- package/dist/_chunks/{logger-C4m8rfMy.js → logger-D1sWX2I0.js} +17 -2
- package/dist/_chunks/logger-D1sWX2I0.js.map +1 -0
- package/dist/_chunks/{node-response-8Vz29cGS.js → node-response-Cp62CtH1.js} +2 -2
- package/dist/_chunks/{node-response-8Vz29cGS.js.map → node-response-Cp62CtH1.js.map} +1 -1
- package/dist/_chunks/{poison-scan-Dpl3ibG-.js → poison-scan-DdkJoHvP.js} +2 -2
- package/dist/_chunks/{poison-scan-Dpl3ibG-.js.map → poison-scan-DdkJoHvP.js.map} +1 -1
- package/dist/_chunks/{scanner-CCEHN9Jg.js → scanner-B6V2RqqF.js} +20 -3
- package/dist/_chunks/scanner-B6V2RqqF.js.map +1 -0
- package/dist/_chunks/{sizeof-CIF7fwSJ.js → sizeof-BKA6qOZq.js} +2 -2
- package/dist/_chunks/{sizeof-CIF7fwSJ.js.map → sizeof-BKA6qOZq.js.map} +1 -1
- package/dist/_chunks/{walkers-BbotBhNG.js → walkers-BAZoAlfI.js} +3 -3
- package/dist/_chunks/{walkers-BbotBhNG.js.map → walkers-BAZoAlfI.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/cli-check.d.ts +3 -3
- package/dist/cli-check.d.ts.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/document-withdrawal.d.ts +2 -0
- package/dist/client/document-withdrawal.d.ts.map +1 -0
- package/dist/client/outlet-content-cache.d.ts +13 -1
- package/dist/client/outlet-content-cache.d.ts.map +1 -1
- package/dist/client/outlet-scope-context.d.ts +5 -0
- package/dist/client/outlet-scope-context.d.ts.map +1 -1
- package/dist/client/segment-outlet.d.ts.map +1 -1
- package/dist/config-types.d.ts +43 -21
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/native/rsc/manifest.json +2 -0
- package/dist/native/rsc/server/als-registry.js.map +1 -1
- package/dist/native/rsc/server/cookie-context.js +7 -7
- package/dist/native/rsc/server/cookie-context.js.map +1 -1
- package/dist/native/rsc/server/deny-boundary.js +2 -1
- package/dist/native/rsc/server/deny-boundary.js.map +1 -1
- package/dist/native/rsc/server/dev-overlay-report.js +13 -0
- package/dist/native/rsc/server/dev-overlay-report.js.map +1 -0
- package/dist/native/rsc/server/logger.js +6 -1
- package/dist/native/rsc/server/logger.js.map +1 -1
- package/dist/native/rsc/server/pipeline-interception.js +4 -1
- package/dist/native/rsc/server/pipeline-interception.js.map +1 -1
- package/dist/native/rsc/server/pipeline.js.map +1 -1
- package/dist/native/rsc/server/request-context.js +4 -4
- package/dist/native/rsc/server/request-context.js.map +1 -1
- package/dist/native/rsc/server/route-element-builder.js +1 -1
- package/dist/native/rsc/server/route-element-builder.js.map +1 -1
- package/dist/native/rsc/server/route-module-loader.js +5 -4
- package/dist/native/rsc/server/route-module-loader.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +1 -1
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/outlet-gate.js +2 -1
- package/dist/native/rsc/server/segment-lifetime/outlet-gate.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/read-rule.js +31 -20
- package/dist/native/rsc/server/segment-lifetime/read-rule.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/read-scope.js +48 -7
- package/dist/native/rsc/server/segment-lifetime/read-scope.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/segment-key.js +13 -8
- package/dist/native/rsc/server/segment-lifetime/segment-key.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js +5 -4
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js.map +1 -1
- package/dist/native/rsc/server/slot-resolver.js +5 -4
- package/dist/native/rsc/server/slot-resolver.js.map +1 -1
- package/dist/native/rsc/server/slot-subtree-contain.js +2 -1
- package/dist/native/rsc/server/slot-subtree-contain.js.map +1 -1
- package/dist/native/rsc/server/subtree-walk.js +14 -5
- package/dist/native/rsc/server/subtree-walk.js.map +1 -1
- package/dist/native/rsc/server/vite-handoff-rsc.js.map +1 -1
- package/dist/native/rsc/shared/key-headers.js +4 -1
- package/dist/native/rsc/shared/key-headers.js.map +1 -1
- package/dist/native/rsc/shared/layout-defaults.js +19 -0
- package/dist/native/rsc/shared/layout-defaults.js.map +1 -0
- package/dist/native/ssr/client/document-withdrawal.js +17 -0
- package/dist/native/ssr/client/document-withdrawal.js.map +1 -0
- package/dist/native/ssr/client/outlet-content-cache.js +6 -1
- 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 +11 -2
- package/dist/native/ssr/client/segment-outlet.js.map +1 -1
- package/dist/native/ssr/manifest.json +6 -0
- package/dist/native/ssr/server/als-registry.js.map +1 -1
- package/dist/native/ssr/server/cookie-context.js +7 -7
- package/dist/native/ssr/server/cookie-context.js.map +1 -1
- package/dist/native/ssr/server/deny-boundary.js +2 -1
- package/dist/native/ssr/server/deny-boundary.js.map +1 -1
- package/dist/native/ssr/server/dev-overlay-report.js +6 -0
- package/dist/native/ssr/server/dev-overlay-report.js.map +1 -0
- package/dist/native/ssr/server/logger.js +6 -1
- package/dist/native/ssr/server/logger.js.map +1 -1
- package/dist/native/ssr/server/pipeline-interception.js +4 -1
- package/dist/native/ssr/server/pipeline-interception.js.map +1 -1
- package/dist/native/ssr/server/pipeline.js.map +1 -1
- package/dist/native/ssr/server/request-context.js +4 -4
- package/dist/native/ssr/server/request-context.js.map +1 -1
- package/dist/native/ssr/server/segment-lifetime/outlet-gate.js +12 -0
- package/dist/native/ssr/server/segment-lifetime/outlet-gate.js.map +1 -0
- package/dist/native/ssr/server/segment-lifetime/read-rule.js +31 -20
- package/dist/native/ssr/server/segment-lifetime/read-rule.js.map +1 -1
- package/dist/native/ssr/server/segment-lifetime/read-scope.js +16 -0
- package/dist/native/ssr/server/segment-lifetime/read-scope.js.map +1 -0
- package/dist/native/ssr/server/subtree-walk.js +149 -0
- package/dist/native/ssr/server/subtree-walk.js.map +1 -0
- package/dist/native/ssr/server/utils/element-type.js +21 -9
- package/dist/native/ssr/server/utils/element-type.js.map +1 -1
- package/dist/native/ssr/server/vite-handoff-rsc.js.map +1 -1
- package/dist/native/ssr/shared/key-headers.js +4 -1
- package/dist/native/ssr/shared/key-headers.js.map +1 -1
- package/dist/native/ssr/shared/layout-defaults.js +9 -0
- package/dist/native/ssr/shared/layout-defaults.js.map +1 -0
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/routing/convention-lint.d.ts +2 -2
- package/dist/routing/convention-lint.d.ts.map +1 -1
- package/dist/routing/index.js +3 -3
- package/dist/routing/route-options-lint.d.ts +2 -2
- package/dist/routing/route-options-lint.d.ts.map +1 -1
- package/dist/routing/slot-placement.d.ts +23 -4
- package/dist/routing/slot-placement.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +18 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/deny-boundary.d.ts.map +1 -1
- package/dist/server/dev-overlay-report.d.ts +13 -0
- package/dist/server/dev-overlay-report.d.ts.map +1 -0
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +97 -8
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts +10 -0
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/pipeline-interception.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts +13 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/route-module-loader.d.ts +4 -3
- package/dist/server/route-module-loader.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +3 -3
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/revalidate-renderer.d.ts +3 -3
- package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
- package/dist/server/segment-lifetime/outlet-gate.d.ts +5 -5
- package/dist/server/segment-lifetime/outlet-gate.d.ts.map +1 -1
- package/dist/server/segment-lifetime/read-rule.d.ts +14 -18
- package/dist/server/segment-lifetime/read-rule.d.ts.map +1 -1
- package/dist/server/segment-lifetime/read-scope.d.ts +47 -6
- package/dist/server/segment-lifetime/read-scope.d.ts.map +1 -1
- package/dist/server/segment-lifetime/segment-key.d.ts +21 -18
- package/dist/server/segment-lifetime/segment-key.d.ts.map +1 -1
- package/dist/server/segment-lifetime/slot-outlets.d.ts +3 -4
- package/dist/server/segment-lifetime/slot-outlets.d.ts.map +1 -1
- package/dist/server/slot-resolver.d.ts.map +1 -1
- package/dist/server/slot-subtree-contain.d.ts.map +1 -1
- package/dist/server/subtree-walk.d.ts +17 -3
- package/dist/server/subtree-walk.d.ts.map +1 -1
- package/dist/server/types.d.ts +4 -3
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/vite-handoff-rsc.d.ts +2 -0
- package/dist/server/vite-handoff-rsc.d.ts.map +1 -1
- package/dist/shared/key-headers.d.ts +2 -0
- package/dist/shared/key-headers.d.ts.map +1 -1
- package/dist/shared/layout-defaults.d.ts +30 -0
- package/dist/shared/layout-defaults.d.ts.map +1 -0
- package/docs/api/30-api-server.mdx +1 -1
- package/docs/api/34-api-config.mdx +20 -3
- package/package.json +1 -1
- package/src/cli-check.ts +6 -6
- package/src/client/document-withdrawal.tsx +41 -0
- package/src/client/outlet-content-cache.ts +18 -2
- package/src/client/outlet-scope-context.ts +5 -0
- package/src/client/segment-outlet.tsx +9 -3
- package/src/config-types.ts +44 -21
- package/src/config-validation.ts +96 -20
- package/src/index.ts +1 -1
- package/src/plugins/entries.ts +6 -3
- package/src/plugins/routing.ts +1 -1
- package/src/routing/convention-lint.ts +5 -3
- package/src/routing/interception.ts +5 -5
- package/src/routing/route-options-lint.ts +6 -6
- package/src/routing/slot-placement.ts +41 -4
- package/src/server/als-registry.ts +14 -0
- package/src/server/cookie-context.ts +7 -7
- package/src/server/deny-boundary.ts +4 -1
- package/src/server/dev-overlay-report.ts +22 -0
- package/src/server/logger.ts +13 -0
- package/src/server/pipeline-interception.ts +11 -2
- package/src/server/pipeline.ts +13 -1
- package/src/server/request-context.ts +6 -6
- package/src/server/route-element-builder.ts +3 -3
- package/src/server/route-module-loader.ts +7 -6
- package/src/server/rsc-entry/index.ts +14 -8
- package/src/server/rsc-entry/render-route.ts +4 -4
- package/src/server/rsc-entry/revalidate-renderer.ts +4 -4
- package/src/server/segment-lifetime/outlet-gate.ts +6 -6
- package/src/server/segment-lifetime/read-rule.ts +67 -33
- package/src/server/segment-lifetime/read-scope.ts +128 -14
- package/src/server/segment-lifetime/segment-key.ts +32 -24
- package/src/server/segment-lifetime/slot-outlets.ts +8 -12
- package/src/server/slot-resolver.ts +22 -10
- package/src/server/slot-subtree-contain.ts +2 -1
- package/src/server/subtree-walk.ts +34 -9
- package/src/server/types.ts +4 -3
- package/src/server/vite-handoff-rsc.ts +2 -0
- package/src/shared/key-headers.ts +5 -0
- package/src/shared/layout-defaults.ts +43 -0
- package/dist/_chunks/actions-BkwgRwCl.js.map +0 -1
- package/dist/_chunks/chains-LGjBHfSN.js +0 -1
- package/dist/_chunks/cli-check-KeE1QaIx.js.map +0 -1
- package/dist/_chunks/convention-lint-0AEsPK2T.js.map +0 -1
- package/dist/_chunks/dev-server-CboXr8zX.js +0 -1
- package/dist/_chunks/key-headers-uIig1_mU.js.map +0 -1
- package/dist/_chunks/logger-C4m8rfMy.js.map +0 -1
- package/dist/_chunks/scanner-CCEHN9Jg.js.map +0 -1
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
* segment's read scope (`read-scope.ts`, design/53-segment-lifetime.md §"What
|
|
4
4
|
* a 'document' segment may read"). No React and no render machinery: the
|
|
5
5
|
* accessors in `request-context.ts` and `cookie-context.ts` import this.
|
|
6
|
+
*
|
|
7
|
+
* A read outside the key is detected and reported in every environment: the
|
|
8
|
+
* dev server's error overlay, or a warning in the log. The read returns its
|
|
9
|
+
* real value, and the component call that read is marked, so its output
|
|
10
|
+
* withdraws the segment from the client (`read-scope.ts`) and the segment renders
|
|
11
|
+
* as `'request'` for that client from then on (design/53 §"Reads outside the key").
|
|
6
12
|
*/
|
|
7
13
|
|
|
8
14
|
import { documentReadScopeAls, type DocumentReadScope } from '../als-registry.ts';
|
|
@@ -10,6 +16,7 @@ import type { CoercedParams } from '../../shared/param-value.ts';
|
|
|
10
16
|
import type { SearchParamsReader } from '../../shared/als-slots.ts';
|
|
11
17
|
import type { ReadonlyHeaders } from '../request-context.ts';
|
|
12
18
|
import { isUnkeyableHeader } from '../../shared/key-headers.ts';
|
|
19
|
+
import { logDocumentReadOutsideKey } from '../logger.ts';
|
|
13
20
|
|
|
14
21
|
/** The read scope the current render runs in, if it is a `'document'` segment's. */
|
|
15
22
|
export function currentReadScope(): DocumentReadScope | undefined {
|
|
@@ -20,33 +27,59 @@ export function currentReadScope(): DocumentReadScope | undefined {
|
|
|
20
27
|
type KeyPart = 'segmentParams' | 'searchParams' | 'cookies' | 'headers';
|
|
21
28
|
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
30
|
+
* Refuse a read outside the key: mark the component call that made it, report
|
|
31
|
+
* it once per segment render (naming the segment, what was read and the fix:
|
|
32
|
+
* add it to the key, or make the segment `'request'`), and return, so the
|
|
33
|
+
* caller performs the read.
|
|
25
34
|
*/
|
|
26
|
-
|
|
35
|
+
function refuseRead(
|
|
27
36
|
scope: DocumentReadScope,
|
|
28
37
|
what: string,
|
|
29
38
|
part?: KeyPart,
|
|
30
39
|
/** Overrides the fix when adding the read to the key is not possible. */
|
|
31
40
|
fixOverride?: string
|
|
41
|
+
): void {
|
|
42
|
+
// A view (`keyedHeaders`, `scopedParams`) keeps the scope it was made in,
|
|
43
|
+
// and can be handed to a component that reads through it later: the call
|
|
44
|
+
// reading now is the one whose output carries the value, so it is marked
|
|
45
|
+
// too (codex on #1317).
|
|
46
|
+
scope.call.read = true;
|
|
47
|
+
const active = currentReadScope();
|
|
48
|
+
if (active) active.call.read = true;
|
|
49
|
+
if (scope.reported.done) return;
|
|
50
|
+
scope.reported.done = true;
|
|
51
|
+
logDocumentReadOutsideKey(readOutsideKey(scope, what, part, fixOverride), {
|
|
52
|
+
segment: scope.segmentPath,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readOutsideKey(
|
|
57
|
+
scope: DocumentReadScope,
|
|
58
|
+
what: string,
|
|
59
|
+
part?: KeyPart,
|
|
60
|
+
fixOverride?: string
|
|
32
61
|
): Error {
|
|
33
62
|
const fix =
|
|
34
63
|
fixOverride ??
|
|
35
64
|
(part
|
|
36
|
-
? `Add it to key.${part}, or declare lifetime: 'request'.`
|
|
65
|
+
? `Add it to key.${part}, or declare lifetime: 'request'.` +
|
|
66
|
+
(part === 'headers'
|
|
67
|
+
? ' A declared key.headers replaces layoutDefaults.key.headers, so list those too.'
|
|
68
|
+
: '')
|
|
37
69
|
: "A 'document' segment cannot depend on it; declare lifetime: 'request'.");
|
|
38
70
|
return new Error(
|
|
39
|
-
`[timber] ${scope.segmentPath} is lifetime: 'document' (declared, or from
|
|
71
|
+
`[timber] ${scope.segmentPath} is lifetime: 'document' (declared, or from layoutDefaults) ` +
|
|
40
72
|
`and read ${what}, which is not in its key. ` +
|
|
41
73
|
`${fix} The segment is skipped without rendering while its key is unchanged, so the read ` +
|
|
42
|
-
`would freeze at its first value
|
|
74
|
+
`would freeze at its first value; until it is fixed, it renders as lifetime: 'request' ` +
|
|
75
|
+
`for this client instead. See design/53-segment-lifetime.md ` +
|
|
43
76
|
`§"What a 'document' segment may read".`
|
|
44
77
|
);
|
|
45
78
|
}
|
|
46
79
|
|
|
47
80
|
/**
|
|
48
81
|
* The request headers as a `'document'` segment may read them: `get` and
|
|
49
|
-
* `has` of a header in its key. Any other name
|
|
82
|
+
* `has` of a header in its key. Any other name is refused, and so is reading
|
|
50
83
|
* them all (iteration, `entries`, `forEach`), which could see headers the
|
|
51
84
|
* key leaves out — the pathname among them.
|
|
52
85
|
*/
|
|
@@ -55,56 +88,58 @@ export function keyedHeaders(headers: ReadonlyHeaders, scope: DocumentReadScope)
|
|
|
55
88
|
if (scope.headers.has(name.toLowerCase())) return name;
|
|
56
89
|
const what = `the header "${name}"`;
|
|
57
90
|
if (name.toLowerCase() === 'cookie') {
|
|
58
|
-
|
|
91
|
+
refuseRead(
|
|
59
92
|
scope,
|
|
60
93
|
what,
|
|
61
94
|
'cookies',
|
|
62
95
|
'Read cookies through a cookie definition in key.cookies.'
|
|
63
96
|
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
throw readOutsideKey(
|
|
97
|
+
} else if (isUnkeyableHeader(name)) {
|
|
98
|
+
refuseRead(
|
|
67
99
|
scope,
|
|
68
100
|
what,
|
|
69
101
|
undefined,
|
|
70
102
|
"A key may not name a credential; declare lifetime: 'request'."
|
|
71
103
|
);
|
|
104
|
+
} else {
|
|
105
|
+
refuseRead(scope, what, 'headers');
|
|
72
106
|
}
|
|
73
|
-
|
|
107
|
+
return name;
|
|
74
108
|
};
|
|
75
|
-
const all = ():
|
|
76
|
-
|
|
109
|
+
const all = (): ReadonlyHeaders => {
|
|
110
|
+
refuseRead(
|
|
77
111
|
scope,
|
|
78
112
|
'every request header',
|
|
79
113
|
undefined,
|
|
80
114
|
"Read each header you need with getHeaders().get(name) and add it to key.headers, or declare lifetime: 'request'."
|
|
81
115
|
);
|
|
116
|
+
return headers;
|
|
82
117
|
};
|
|
83
118
|
return {
|
|
84
119
|
get: (name) => headers.get(keyed(name)),
|
|
85
120
|
has: (name) => headers.has(keyed(name)),
|
|
86
|
-
entries: all,
|
|
87
|
-
keys: all,
|
|
88
|
-
values: all,
|
|
89
|
-
forEach: all,
|
|
90
|
-
[Symbol.iterator]: all,
|
|
121
|
+
entries: () => all().entries(),
|
|
122
|
+
keys: () => all().keys(),
|
|
123
|
+
values: () => all().values(),
|
|
124
|
+
forEach: (callback, thisArg) => all().forEach(callback, thisArg),
|
|
125
|
+
[Symbol.iterator]: () => all()[Symbol.iterator](),
|
|
91
126
|
};
|
|
92
127
|
}
|
|
93
128
|
|
|
94
|
-
/**
|
|
95
|
-
export function
|
|
129
|
+
/** Refuse the read if the current render may not read `what` at all (raw search params). */
|
|
130
|
+
export function checkUnscopedRead(what: string): void {
|
|
96
131
|
const scope = currentReadScope();
|
|
97
|
-
if (scope)
|
|
132
|
+
if (scope) refuseRead(scope, what);
|
|
98
133
|
}
|
|
99
134
|
|
|
100
135
|
/**
|
|
101
|
-
*
|
|
136
|
+
* Refuse the read if the current render reads search-param fields outside its key. A
|
|
102
137
|
* field is in the key only when the key's definition reads it through the
|
|
103
138
|
* same codec and URL key — a `.pick()` of the keyed definition, or the keyed
|
|
104
139
|
* definition itself. Another definition with a field of the same name may map
|
|
105
140
|
* it to another URL parameter or parse it differently.
|
|
106
141
|
*/
|
|
107
|
-
export function
|
|
142
|
+
export function checkSearchParamsRead(reader: SearchParamsReader): void {
|
|
108
143
|
const scope = currentReadScope();
|
|
109
144
|
if (!scope) return;
|
|
110
145
|
const outside = Object.keys(reader.codecs).filter((field) => {
|
|
@@ -116,24 +151,23 @@ export function assertSearchParamsRead(reader: SearchParamsReader): void {
|
|
|
116
151
|
);
|
|
117
152
|
});
|
|
118
153
|
if (outside.length > 0) {
|
|
119
|
-
|
|
154
|
+
refuseRead(scope, `the search params ${outside.join(', ')}`, 'searchParams');
|
|
120
155
|
}
|
|
121
156
|
}
|
|
122
157
|
|
|
123
158
|
/**
|
|
124
|
-
*
|
|
159
|
+
* Refuse the read if the current render reads a cookie outside its key. A keyed cookie
|
|
125
160
|
* is in the key only as its definition parses it, so it may be read only
|
|
126
161
|
* through that definition (`codec` is the reader's); a raw read, or another
|
|
127
162
|
* definition of the same name, could see a difference the key does not.
|
|
128
163
|
*/
|
|
129
|
-
export function
|
|
164
|
+
export function checkCookieRead(name: string, codec?: unknown): void {
|
|
130
165
|
const scope = currentReadScope();
|
|
131
166
|
if (!scope) return;
|
|
132
167
|
if (!scope.cookies.has(name)) {
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
throw readOutsideKey(
|
|
168
|
+
refuseRead(scope, `the cookie "${name}"`, 'cookies');
|
|
169
|
+
} else if (codec === undefined || scope.cookies.get(name) !== codec) {
|
|
170
|
+
refuseRead(
|
|
137
171
|
scope,
|
|
138
172
|
`the raw value of the cookie "${name}" (read it through the definition in its key)`,
|
|
139
173
|
'cookies'
|
|
@@ -157,7 +191,7 @@ const OBJECT_PROBES: ReadonlySet<string> = new Set([
|
|
|
157
191
|
]);
|
|
158
192
|
|
|
159
193
|
/**
|
|
160
|
-
* The params a scoped render sees: reading one outside the key
|
|
194
|
+
* The params a scoped render sees: reading one outside the key is refused. Its
|
|
161
195
|
* own keys are only the params in the key, so spreading it, or passing it to
|
|
162
196
|
* a client component, carries exactly what the segment may depend on.
|
|
163
197
|
*/
|
|
@@ -181,7 +215,7 @@ export function scopedParams<T extends CoercedParams>(params: T): T {
|
|
|
181
215
|
return new Proxy(target, {
|
|
182
216
|
get(target, name, receiver) {
|
|
183
217
|
if (refused(name)) {
|
|
184
|
-
|
|
218
|
+
refuseRead(scope, `the segment param "${String(name)}"`, 'segmentParams');
|
|
185
219
|
}
|
|
186
220
|
return Reflect.get(target, name, receiver);
|
|
187
221
|
},
|
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A `'document'` segment is skipped without rendering whenever its key is
|
|
7
7
|
* unchanged, so anything else it read would freeze silently at its load-time
|
|
8
|
-
* value. The rule
|
|
8
|
+
* value. The rule detects that in every environment, reports it (the dev
|
|
9
|
+
* overlay, or a warning in the log), and degrades the segment to `'request'`
|
|
10
|
+
* for the client (below). What it refuses:
|
|
9
11
|
*
|
|
10
|
-
* - `getSegmentParams()` returns a view that
|
|
11
|
-
* - a search-params definition's `.get()`
|
|
12
|
-
* in the key's definition, and the raw search params
|
|
13
|
-
* - the cookie jar
|
|
12
|
+
* - `getSegmentParams()` returns a view that refuses a param outside the key;
|
|
13
|
+
* - a search-params definition's `.get()` is refused unless every field it
|
|
14
|
+
* reads is in the key's definition, and so are the raw search params;
|
|
15
|
+
* - the cookie jar refuses a cookie outside the key, and `getAll()`;
|
|
14
16
|
* - `getHeaders()` reads only the headers in the key; any other header, and
|
|
15
|
-
* iterating them all,
|
|
17
|
+
* iterating them all, is refused — and with that the pathname, which no timber
|
|
16
18
|
* API exposes to a component except through a header.
|
|
17
19
|
*
|
|
18
20
|
* **Reach.** The scope is an AsyncLocalStorage scope around the segment's
|
|
@@ -26,13 +28,50 @@
|
|
|
26
28
|
* Not covered: values computed outside this render and handed to it — a
|
|
27
29
|
* `timber.cache` entry an earlier request filled, or a module-level value. The
|
|
28
30
|
* accessors' checks are `read-rule.ts`.
|
|
31
|
+
*
|
|
32
|
+
* **Degrading.** The read rule reports a refused read, lets it return its
|
|
33
|
+
* real value and marks the component call that made it: each scoped call runs
|
|
34
|
+
* in its own copy of the scope, with a fresh `call` record. The render has
|
|
35
|
+
* already sent the outlet's key digest (the outlet decides before the segment
|
|
36
|
+
* renders), so the content withdraws itself instead: when a call that read
|
|
37
|
+
* outside the key returns, its output gets a `DocumentWithdrawal` marker. The
|
|
38
|
+
* marker sits beside what the read produced, so the client commits it exactly
|
|
39
|
+
* when it commits that content — not in a Suspense fallback or an unrendered
|
|
40
|
+
* prop another component happened to finish in. When it commits, the client
|
|
41
|
+
* drops the segment's entry and records none for that outlet for the rest of
|
|
42
|
+
* the document (`client/outlet-content-cache.ts`). The client never advertises
|
|
43
|
+
* a digest for it again, so every later navigation renders it live —
|
|
44
|
+
* `'request'` for that client.
|
|
45
|
+
*
|
|
46
|
+
* A call that reads and then throws has no output to mark. Its error is
|
|
47
|
+
* remembered, and each catcher that renders a fallback in its place inside an
|
|
48
|
+
* outlet (a deny page, a slot's `default.tsx`) passes the fallback through
|
|
49
|
+
* `fallbackAfter`, which marks it. The marker withdraws whichever outlet the
|
|
50
|
+
* fallback lands in.
|
|
51
|
+
*
|
|
52
|
+
* An async iterable the call returned is advanced later, in a call record of
|
|
53
|
+
* its own; the first chunk it yields after a read carries the marker, or, for
|
|
54
|
+
* a read on its closing step, a last chunk of the marker alone.
|
|
55
|
+
*
|
|
56
|
+
* A scoped view (`getHeaders()`, `getSegmentParams()`) handed down to another
|
|
57
|
+
* component marks the call reading through it, as well as the one that made it.
|
|
58
|
+
*
|
|
59
|
+
* Not marked: a read in other work the call did not await, such as a promise
|
|
60
|
+
* handed to a client component (it lands in a call record nobody checks).
|
|
61
|
+
* See design/53 §"Reads outside the key".
|
|
29
62
|
*/
|
|
30
63
|
|
|
31
|
-
import { createElement, type ReactNode } from 'react';
|
|
64
|
+
import { createElement, Fragment, type ReactElement, type ReactNode } from 'react';
|
|
32
65
|
|
|
33
66
|
import { documentReadScopeAls, type DocumentReadScope } from '../als-registry.ts';
|
|
34
67
|
import { isOutletGateElement } from './outlet-gate.ts';
|
|
35
|
-
import {
|
|
68
|
+
import {
|
|
69
|
+
callAndRewrite,
|
|
70
|
+
isThenable,
|
|
71
|
+
type ServerComponent,
|
|
72
|
+
type SubtreeRule,
|
|
73
|
+
} from '../subtree-walk.ts';
|
|
74
|
+
import { clientComponents } from '../vite-handoff-rsc.ts';
|
|
36
75
|
import type { DocumentLifetime } from './segment-key.ts';
|
|
37
76
|
|
|
38
77
|
/** The read scope of one `'document'` segment. */
|
|
@@ -53,6 +92,8 @@ export function readScopeFor(
|
|
|
53
92
|
),
|
|
54
93
|
cookies: new Map((key.cookies ?? []).map((cookie) => [cookie.name, cookie.codec])),
|
|
55
94
|
headers: new Set((key.headers ?? []).map((name) => name.toLowerCase())),
|
|
95
|
+
reported: { done: false },
|
|
96
|
+
call: { read: false },
|
|
56
97
|
};
|
|
57
98
|
}
|
|
58
99
|
|
|
@@ -62,7 +103,7 @@ export function readScopeFor(
|
|
|
62
103
|
*/
|
|
63
104
|
export function inReadScope(component: ServerComponent, scope: DocumentReadScope): ServerComponent {
|
|
64
105
|
const rule = scopeRule(scope);
|
|
65
|
-
return (props) =>
|
|
106
|
+
return (props) => runCall(scope, () => callAndRewrite(component, props, rule));
|
|
66
107
|
}
|
|
67
108
|
|
|
68
109
|
/**
|
|
@@ -77,9 +118,66 @@ function ScopedServerComponent(props: {
|
|
|
77
118
|
scope: DocumentReadScope;
|
|
78
119
|
}): ReactNode | Promise<ReactNode> {
|
|
79
120
|
const { component, componentProps, scope } = props;
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
121
|
+
return runCall(scope, () => callAndRewrite(component, componentProps, scopeRule(scope)));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Run one scoped component call in its own copy of the scope — a fresh
|
|
126
|
+
* `call` record, the segment's shared `reported` — and append the client's
|
|
127
|
+
* withdrawal marker to its output if the call, or work it awaited, read
|
|
128
|
+
* outside the key.
|
|
129
|
+
*/
|
|
130
|
+
function runCall(
|
|
131
|
+
scope: DocumentReadScope,
|
|
132
|
+
call: () => ReactNode | Promise<ReactNode>
|
|
133
|
+
): ReactNode | Promise<ReactNode> {
|
|
134
|
+
const frame: DocumentReadScope = { ...scope, call: { read: false } };
|
|
135
|
+
const thrown = (error: unknown): never => {
|
|
136
|
+
if (frame.call.read && typeof error === 'object' && error !== null) {
|
|
137
|
+
THROWN_AFTER_READ.add(error);
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
};
|
|
141
|
+
let output: ReactNode | Promise<ReactNode>;
|
|
142
|
+
try {
|
|
143
|
+
output = documentReadScopeAls.run(frame, call);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return thrown(error);
|
|
146
|
+
}
|
|
147
|
+
if (isThenable(output)) {
|
|
148
|
+
return Promise.resolve(output).then(
|
|
149
|
+
(node) => (frame.call.read ? withMarker(node) : node),
|
|
150
|
+
thrown
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return frame.call.read ? withMarker(output) : output;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Errors thrown by a scoped call after it read outside its key. Weak: an
|
|
158
|
+
* error lives only as long as whoever handles it holds it.
|
|
159
|
+
*/
|
|
160
|
+
const THROWN_AFTER_READ = new WeakSet<object>();
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The fallback a catcher renders in place of a component that threw: marked
|
|
164
|
+
* to withdraw its outlet when the throw came from a scoped call that read
|
|
165
|
+
* outside its key, so the client does not keep the fallback under the key
|
|
166
|
+
* digest. Every catcher that renders a fallback inside an outlet calls this.
|
|
167
|
+
*/
|
|
168
|
+
export function fallbackAfter<T extends ReactNode>(error: unknown, fallback: T): T | ReactElement {
|
|
169
|
+
const marked = typeof error === 'object' && error !== null && THROWN_AFTER_READ.has(error);
|
|
170
|
+
return marked ? withMarker(fallback) : fallback;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* `node` with a `DocumentWithdrawal` marker beside it. Two arguments, not an
|
|
175
|
+
* array: no key is needed, and `node` keeps its position as the fragment's
|
|
176
|
+
* first child.
|
|
177
|
+
*/
|
|
178
|
+
function withMarker(node: ReactNode): ReactElement {
|
|
179
|
+
const { DocumentWithdrawal } = clientComponents();
|
|
180
|
+
return createElement(Fragment, null, node, createElement(DocumentWithdrawal));
|
|
83
181
|
}
|
|
84
182
|
|
|
85
183
|
function scopeRule(scope: DocumentReadScope): SubtreeRule {
|
|
@@ -95,7 +193,23 @@ function scopeRule(scope: DocumentReadScope): SubtreeRule {
|
|
|
95
193
|
}),
|
|
96
194
|
// A nested outlet is another segment: its own lifetime decides what it reads.
|
|
97
195
|
isOpaque: isOutletGateElement,
|
|
98
|
-
// An async iterable it returned reads, as it is advanced, inside the scope
|
|
99
|
-
|
|
196
|
+
// An async iterable it returned reads, as it is advanced, inside the scope:
|
|
197
|
+
// in a call record of its own, so a chunk produced after a read outside
|
|
198
|
+
// the key carries the marker as a call's output would.
|
|
199
|
+
// Marked once: the marker commits with that chunk, and each marked chunk
|
|
200
|
+
// becomes an element, which an iterable read as data would notice. A read
|
|
201
|
+
// on the closing step yields the marker alone, since the return value is
|
|
202
|
+
// not rendered (codex on #1317).
|
|
203
|
+
iterate: () => {
|
|
204
|
+
const frame: DocumentReadScope = { ...scope, call: { read: false } };
|
|
205
|
+
let marked = false;
|
|
206
|
+
const due = () => frame.call.read && !marked && (marked = true);
|
|
207
|
+
return {
|
|
208
|
+
run: (fn) => documentReadScopeAls.run(frame, fn),
|
|
209
|
+
// What an async iterable rendered as a child yields is rendered as nodes.
|
|
210
|
+
yielded: (value) => (due() ? withMarker(value as ReactNode) : value),
|
|
211
|
+
beforeClose: () => (due() ? withMarker(null) : undefined),
|
|
212
|
+
};
|
|
213
|
+
},
|
|
100
214
|
};
|
|
101
215
|
}
|
|
@@ -26,8 +26,9 @@ import type { CoercedParams } from '../../shared/param-value.ts';
|
|
|
26
26
|
import { ROUTE_OPTIONS_EXPORT, type RouteOptionsKind } from '../../shared/route-options-export.ts';
|
|
27
27
|
import { getCookieJar } from '../cookie-context.ts';
|
|
28
28
|
import { getHeaders, getSearchParams } from '../request-context.ts';
|
|
29
|
-
import { headerKeyProblem } from '../../shared/key-headers.ts';
|
|
30
|
-
import
|
|
29
|
+
import { headerKeyProblem, isHeaderList } from '../../shared/key-headers.ts';
|
|
30
|
+
import { NO_LAYOUT_DEFAULTS, type ResolvedLayoutDefaults } from '../../shared/layout-defaults.ts';
|
|
31
|
+
import type { SegmentKey } from '../types.ts';
|
|
31
32
|
|
|
32
33
|
/** A segment declared `lifetime: 'document'`, with the key it declared (if any). */
|
|
33
34
|
export interface DocumentLifetime {
|
|
@@ -35,45 +36,52 @@ export interface DocumentLifetime {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
|
-
* The
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* A page always defaults to `'request'`.
|
|
39
|
+
* The defaults of the layout at the end of `chain` (the segments from the
|
|
40
|
+
* root down to it, slot chains included): the app's `layoutDefaults`, except
|
|
41
|
+
* at or below an intercepting segment. Options there are a build error
|
|
42
|
+
* (`routing/route-options-lint.ts`), so a defaulted layout under an
|
|
43
|
+
* intercepting directory could never opt out — it takes no defaults instead
|
|
44
|
+
* (design/53 §"App-wide defaults"). A page always takes `NO_LAYOUT_DEFAULTS`.
|
|
45
45
|
*/
|
|
46
|
-
export function
|
|
46
|
+
export function layoutDefaultsAt(
|
|
47
47
|
chain: readonly { segmentType?: string }[],
|
|
48
|
-
|
|
49
|
-
):
|
|
50
|
-
|
|
48
|
+
appDefaults: ResolvedLayoutDefaults
|
|
49
|
+
): ResolvedLayoutDefaults {
|
|
50
|
+
const intercepted = chain.some((segment) => segment.segmentType === 'intercepting');
|
|
51
|
+
return intercepted ? NO_LAYOUT_DEFAULTS : appDefaults;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* The module's lifetime: a `DocumentLifetime` when its options object
|
|
55
|
-
* declares `lifetime: 'document'`, or declares no lifetime and
|
|
56
|
-
* `
|
|
57
|
-
*
|
|
58
|
-
* what takes effect.
|
|
56
|
+
* declares `lifetime: 'document'`, or declares no lifetime and the default is
|
|
57
|
+
* `'document'`; undefined otherwise. The build validated the object from
|
|
58
|
+
* source (`routing/route-options.ts`); this runtime read is what takes effect.
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* Each key part defaults on its own, as `segmentParams` already does: a
|
|
61
|
+
* `'document'` segment whose key omits `headers` takes the default headers,
|
|
62
|
+
* and one that declares `headers` replaces them.
|
|
63
|
+
*
|
|
64
|
+
* @param defaults What a module that declares none takes: the app's
|
|
65
|
+
* `layoutDefaults` for a layout (`layoutDefaultsAt`), `NO_LAYOUT_DEFAULTS`
|
|
66
|
+
* for a page (design/53 §"App-wide defaults").
|
|
63
67
|
*/
|
|
64
68
|
export function readDocumentLifetime(
|
|
65
69
|
mod: Record<string, unknown>,
|
|
66
70
|
kind: RouteOptionsKind,
|
|
67
|
-
|
|
71
|
+
defaults: ResolvedLayoutDefaults
|
|
68
72
|
): DocumentLifetime | undefined {
|
|
69
73
|
const exported = mod[ROUTE_OPTIONS_EXPORT[kind]];
|
|
70
74
|
const options = typeof exported === 'object' && exported !== null ? exported : {};
|
|
71
75
|
const lifetime = 'lifetime' in options ? options.lifetime : undefined;
|
|
72
|
-
if ((lifetime ??
|
|
76
|
+
if ((lifetime ?? defaults.lifetime) !== 'document') return undefined;
|
|
73
77
|
const key = 'key' in options ? options.key : undefined;
|
|
74
78
|
// The module's own export, typed `satisfies LayoutOptions` / `PageOptions`
|
|
75
79
|
// in source and shape-checked by the build; at runtime it is an `object`.
|
|
76
|
-
const
|
|
80
|
+
const declared = typeof key === 'object' && key !== null ? (key as SegmentKey) : {};
|
|
81
|
+
const segmentKey =
|
|
82
|
+
declared.headers === undefined && defaults.headers !== undefined
|
|
83
|
+
? { ...declared, headers: defaults.headers }
|
|
84
|
+
: declared;
|
|
77
85
|
assertKeyableHeaders(segmentKey.headers);
|
|
78
86
|
return { key: segmentKey };
|
|
79
87
|
}
|
|
@@ -85,7 +93,7 @@ export function readDocumentLifetime(
|
|
|
85
93
|
*/
|
|
86
94
|
function assertKeyableHeaders(headers: unknown): void {
|
|
87
95
|
if (headers === undefined) return;
|
|
88
|
-
if (!
|
|
96
|
+
if (!isHeaderList(headers)) {
|
|
89
97
|
throw new Error('[timber] key.headers must be an array of header names.');
|
|
90
98
|
}
|
|
91
99
|
for (const name of headers) {
|
|
@@ -31,11 +31,8 @@ import type { CoercedParams } from '../../shared/param-value.ts';
|
|
|
31
31
|
import type { ManifestSegmentNode } from '../route-matcher.ts';
|
|
32
32
|
import { outletGate, type OutletSpec, type SegmentRender } from './outlet-gate.ts';
|
|
33
33
|
import { documentOutletFor } from './document-outlet.ts';
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
readDocumentLifetime,
|
|
37
|
-
type DocumentLifetime,
|
|
38
|
-
} from './segment-key.ts';
|
|
34
|
+
import { layoutDefaultsAt, readDocumentLifetime, type DocumentLifetime } from './segment-key.ts';
|
|
35
|
+
import { NO_LAYOUT_DEFAULTS } from '../../shared/layout-defaults.ts';
|
|
39
36
|
import { inReadScope, readScopeFor } from './read-scope.ts';
|
|
40
37
|
import type { ServerComponent } from '../subtree-walk.ts';
|
|
41
38
|
|
|
@@ -73,19 +70,18 @@ export class SlotDocumentOutlets {
|
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
/**
|
|
76
|
-
* A slot segment's lifetime: its own declaration,
|
|
77
|
-
* `
|
|
78
|
-
* `'request'` for a page.
|
|
73
|
+
* A slot segment's lifetime: its own declaration, over the app's
|
|
74
|
+
* `layoutDefaults` for a layout (`layoutDefaultsAt`) and none for a page.
|
|
79
75
|
*/
|
|
80
76
|
lifetimeOf(
|
|
81
77
|
node: ManifestSegmentNode,
|
|
82
78
|
mod: Record<string, unknown>,
|
|
83
79
|
kind: 'page' | 'layout'
|
|
84
80
|
): DocumentLifetime | undefined {
|
|
85
|
-
if (kind === 'page') return readDocumentLifetime(mod, kind,
|
|
81
|
+
if (kind === 'page') return readDocumentLifetime(mod, kind, NO_LAYOUT_DEFAULTS);
|
|
86
82
|
const chain = [...this.ctx.ownerChain, ...this.ctx.chain.slice(0, this.depth(node) + 1)];
|
|
87
|
-
const
|
|
88
|
-
return readDocumentLifetime(mod, kind,
|
|
83
|
+
const defaults = layoutDefaultsAt(chain, this.ctx.render.layoutDefaults);
|
|
84
|
+
return readDocumentLifetime(mod, kind, defaults);
|
|
89
85
|
}
|
|
90
86
|
|
|
91
87
|
/** Wrap a `'document'` slot page in its own outlet. */
|
|
@@ -133,7 +129,7 @@ export class SlotDocumentOutlets {
|
|
|
133
129
|
|
|
134
130
|
/**
|
|
135
131
|
* A 'document' slot segment's component, run in its read scope
|
|
136
|
-
* (`read-scope.ts`): a read outside its key
|
|
132
|
+
* (`read-scope.ts`): a read outside its key is refused.
|
|
137
133
|
*/
|
|
138
134
|
scoped(
|
|
139
135
|
node: ManifestSegmentNode,
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
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';
|
|
45
|
+
import { fallbackAfter } from './segment-lifetime/read-scope.ts';
|
|
45
46
|
import type { ServerComponent } from './subtree-walk.ts';
|
|
46
47
|
import { clientComponents } from './vite-handoff-rsc.ts';
|
|
47
48
|
|
|
@@ -99,13 +100,22 @@ export async function resolveSlotElement(
|
|
|
99
100
|
parentTreePath?: string,
|
|
100
101
|
render: SegmentRender = LIVE_ONLY_RENDER
|
|
101
102
|
): Promise<ResolvedSlotElement> {
|
|
102
|
-
// When interception is active
|
|
103
|
-
//
|
|
104
|
-
// it instead of the normal slot match
|
|
105
|
-
// the slot shows the intercepted content on soft
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
// When interception is active and this slot belongs to the winning owner,
|
|
104
|
+
// try to match intercepting children in this slot against the target
|
|
105
|
+
// pathname. If one matches, render it instead of the normal slot match —
|
|
106
|
+
// the modal pattern: the slot shows the intercepted content on soft
|
|
107
|
+
// navigation.
|
|
108
|
+
//
|
|
109
|
+
// The owner test consumes the pipeline's decision; it does not re-derive
|
|
110
|
+
// one. A slot on any other owner of the chain resolves as it would on a
|
|
111
|
+
// navigation nothing intercepted, even when it holds an interceptor for this
|
|
112
|
+
// very URL: that interceptor lost the deepest-scope ranking (TIM-1443). Two
|
|
113
|
+
// slots on the winning owner both intercept, one modal each — design/07
|
|
114
|
+
// §"Selection Between Owners".
|
|
115
|
+
const intercepting =
|
|
116
|
+
interception && interception.interceptingScope === parentTreePath
|
|
117
|
+
? findInterceptingMatch(slotNode, interception.targetPathname)
|
|
118
|
+
: null;
|
|
109
119
|
const slotMatch = intercepting ?? findSlotMatch(slotNode, match);
|
|
110
120
|
|
|
111
121
|
if (slotMatch) {
|
|
@@ -204,14 +214,16 @@ export async function resolveSlotElement(
|
|
|
204
214
|
if (isRedirectSignal(error)) {
|
|
205
215
|
throw error;
|
|
206
216
|
}
|
|
217
|
+
// A 'document' slot page that read outside its key and then threw
|
|
218
|
+
// must not have its fallback kept under the key digest (design/53).
|
|
207
219
|
if (isDenySignal(error)) {
|
|
208
|
-
return denyFallback;
|
|
220
|
+
return fallbackAfter(error, denyFallback);
|
|
209
221
|
}
|
|
210
222
|
// Report the error but don't re-throw — returning fallback ensures
|
|
211
223
|
// the Flight row is resolved and the page hydrates correctly.
|
|
212
224
|
// Nothing downstream sees it, so this is its one report.
|
|
213
225
|
reportRenderError(error, req, { segments: match.segments });
|
|
214
|
-
return denyFallback;
|
|
226
|
+
return fallbackAfter(error, denyFallback);
|
|
215
227
|
}
|
|
216
228
|
};
|
|
217
229
|
element = h(SafeSlotPage, {});
|
|
@@ -389,7 +401,7 @@ function ScopedSlotLayout(props: {
|
|
|
389
401
|
props.scope(() => props.layout({ children: props.children }))
|
|
390
402
|
);
|
|
391
403
|
} catch (error) {
|
|
392
|
-
if (isDenySignal(error)) return props.denyFallback;
|
|
404
|
+
if (isDenySignal(error)) return fallbackAfter(error, props.denyFallback);
|
|
393
405
|
throw error;
|
|
394
406
|
}
|
|
395
407
|
return containSlotSubtree(rendered as React.ReactNode, props.denyFallback, props.children);
|
|
@@ -43,10 +43,11 @@ import {
|
|
|
43
43
|
type ServerComponent,
|
|
44
44
|
type SubtreeRule,
|
|
45
45
|
} from './subtree-walk.ts';
|
|
46
|
+
import { fallbackAfter } from './segment-lifetime/read-scope.ts';
|
|
46
47
|
|
|
47
48
|
function denyToFallback(fallback: ReactNode): (error: unknown) => ReactNode {
|
|
48
49
|
return (error) => {
|
|
49
|
-
if (isDenySignal(error)) return fallback;
|
|
50
|
+
if (isDenySignal(error)) return fallbackAfter(error, fallback);
|
|
50
51
|
throw error;
|
|
51
52
|
};
|
|
52
53
|
}
|