@timber-js/app 0.2.0-alpha.240 → 0.2.0-alpha.241
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-DIgnvDrG.js → actions-BCYVyoFl.js} +117 -11
- package/dist/_chunks/actions-BCYVyoFl.js.map +1 -0
- package/dist/_chunks/{als-registry-PPYstxK0.js → als-registry-fabsRnPY.js} +4 -2
- package/dist/_chunks/{als-registry-PPYstxK0.js.map → als-registry-fabsRnPY.js.map} +1 -1
- package/dist/_chunks/{als-slots-kbQrHTzm.js → als-slots-CVTF-AMz.js} +3 -3
- package/dist/_chunks/als-slots-CVTF-AMz.js.map +1 -0
- package/dist/_chunks/{cache-api-uWQwuxWb.js → cache-api-n5FL4wFs.js} +5 -5
- package/dist/_chunks/{cache-api-uWQwuxWb.js.map → cache-api-n5FL4wFs.js.map} +1 -1
- package/dist/_chunks/chains-DPZAMMav.js +1 -0
- package/dist/_chunks/{chains-C7CExrUI.js → chains-IswOWMnq.js} +2 -2
- package/dist/_chunks/{chains-C7CExrUI.js.map → chains-IswOWMnq.js.map} +1 -1
- package/dist/_chunks/{classify-Cj9EeZoL.js → classify-B08RCF6s.js} +2 -2
- package/dist/_chunks/{classify-Cj9EeZoL.js.map → classify-B08RCF6s.js.map} +1 -1
- package/dist/_chunks/{cli-check-C3QOAru7.js → cli-check-tpFb6pBU.js} +7 -6
- package/dist/_chunks/cli-check-tpFb6pBU.js.map +1 -0
- package/dist/_chunks/{cli-schema-sync-BRxZz66D.js → cli-schema-sync-C0pXBtzG.js} +1 -1
- package/dist/_chunks/{cli-schema-sync-DQUS_o3V.js → cli-schema-sync-DRNJutey.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-DQUS_o3V.js.map → cli-schema-sync-DRNJutey.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-ZETBdLgv.js → client-dep-entries-Dw5Dvatr.js} +2 -2
- package/dist/_chunks/{client-dep-entries-ZETBdLgv.js.map → client-dep-entries-Dw5Dvatr.js.map} +1 -1
- package/dist/_chunks/{cloudflare-Dk5Hqo-O.js → cloudflare-9dbhVOxS.js} +2 -2
- package/dist/_chunks/{cloudflare-Dk5Hqo-O.js.map → cloudflare-9dbhVOxS.js.map} +1 -1
- package/dist/_chunks/{convention-lint-BoVISNS6.js → convention-lint-BfC_dAhZ.js} +364 -10
- package/dist/_chunks/convention-lint-BfC_dAhZ.js.map +1 -0
- package/dist/_chunks/dev-server-3DNTXQV-.js +1 -0
- package/dist/_chunks/{dev-server-C5R6jx8Q.js → dev-server-3R6Bl9_R.js} +9 -2
- package/dist/_chunks/dev-server-3R6Bl9_R.js.map +1 -0
- package/dist/_chunks/{dist-C1Rjlo6s.js → dist-GyaJm4GA.js} +18 -2
- package/dist/_chunks/dist-GyaJm4GA.js.map +1 -0
- package/dist/_chunks/{error-boundary-DB51f9ih.js → error-boundary-Dfhxigko.js} +8 -4
- package/dist/_chunks/error-boundary-Dfhxigko.js.map +1 -0
- package/dist/_chunks/{flight-source-node-D9cHBhjP.js → flight-source-node-QOpWZATb.js} +2 -2
- package/dist/_chunks/{flight-source-node-D9cHBhjP.js.map → flight-source-node-QOpWZATb.js.map} +1 -1
- package/dist/_chunks/{json-lossy-check-Y1GxqVX_.js → json-lossy-check-5KFcC1yt.js} +2 -2
- package/dist/_chunks/{json-lossy-check-Y1GxqVX_.js.map → json-lossy-check-5KFcC1yt.js.map} +1 -1
- package/dist/_chunks/{live-graph-BDQWvnMm.js → live-graph-D1dfVqoT.js} +4 -4
- package/dist/_chunks/{live-graph-BDQWvnMm.js.map → live-graph-D1dfVqoT.js.map} +1 -1
- package/dist/_chunks/{logger-DmRR9tmZ.js → logger-BvGxPd1e.js} +2 -2
- package/dist/_chunks/{logger-DmRR9tmZ.js.map → logger-BvGxPd1e.js.map} +1 -1
- package/dist/_chunks/metadata-routes-MXNjWOt5.js.map +1 -1
- package/dist/_chunks/{node-response-yp8zdyRp.js → node-response-D5cfiyWP.js} +2 -2
- package/dist/_chunks/{node-response-yp8zdyRp.js.map → node-response-D5cfiyWP.js.map} +1 -1
- package/dist/_chunks/{poison-scan-WQgUydF_.js → poison-scan-CX02ilxN.js} +2 -2
- package/dist/_chunks/{poison-scan-WQgUydF_.js.map → poison-scan-CX02ilxN.js.map} +1 -1
- package/dist/_chunks/{rsc-cache-key-D0cb0Gmc.js → rsc-cache-key-BGvUtMtN.js} +40 -4
- package/dist/_chunks/{rsc-cache-key-D0cb0Gmc.js.map → rsc-cache-key-BGvUtMtN.js.map} +1 -1
- package/dist/_chunks/{scanner-C9Lrf77z.js → scanner-DneYxQoY.js} +14 -81
- package/dist/_chunks/scanner-DneYxQoY.js.map +1 -0
- package/dist/_chunks/{sizeof-BISkSaU0.js → sizeof-BtQ3ErLf.js} +2 -2
- package/dist/_chunks/{sizeof-BISkSaU0.js.map → sizeof-BtQ3ErLf.js.map} +1 -1
- package/dist/_chunks/{walkers-Bxv4v7tX.js → walkers-C9R2A4jN.js} +3 -3
- package/dist/_chunks/{walkers-Bxv4v7tX.js.map → walkers-C9R2A4jN.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +2 -2
- package/dist/adapters/cloudflare.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-check.d.ts +3 -0
- package/dist/cli-check.d.ts.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/internal.js +3 -2
- package/dist/client/internal.js.map +1 -1
- package/dist/client/navigation-commit.d.ts +5 -0
- package/dist/client/navigation-commit.d.ts.map +1 -1
- package/dist/client/outlet-content-cache.d.ts +28 -7
- package/dist/client/outlet-content-cache.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/segment-outlet.d.ts +3 -1
- package/dist/client/segment-outlet.d.ts.map +1 -1
- package/dist/config-types.d.ts +24 -0
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/cookies/define-cookie.d.ts.map +1 -1
- package/dist/cookies/index.js +5 -2
- package/dist/cookies/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +109 -25
- package/dist/index.js.map +1 -1
- package/dist/native/rsc/cookies/define-cookie.js +6 -2
- package/dist/native/rsc/cookies/define-cookie.js.map +1 -1
- package/dist/native/rsc/manifest.json +10 -0
- package/dist/native/rsc/routing/segment-keys.js +11 -1
- package/dist/native/rsc/routing/segment-keys.js.map +1 -1
- package/dist/native/rsc/search-params/define.js +4 -1
- package/dist/native/rsc/search-params/define.js.map +1 -1
- package/dist/native/rsc/server/als-registry.js +2 -1
- package/dist/native/rsc/server/als-registry.js.map +1 -1
- package/dist/native/rsc/server/client-state-tree.js +14 -9
- package/dist/native/rsc/server/client-state-tree.js.map +1 -1
- package/dist/native/rsc/server/cookie-context.js +12 -0
- package/dist/native/rsc/server/cookie-context.js.map +1 -1
- package/dist/native/rsc/server/flight-source.js +5 -2
- package/dist/native/rsc/server/flight-source.js.map +1 -1
- package/dist/native/rsc/server/framework-stack-frames.js +18 -0
- package/dist/native/rsc/server/framework-stack-frames.js.map +1 -0
- package/dist/native/rsc/server/prebuilt-builder.js +15 -1
- package/dist/native/rsc/server/prebuilt-builder.js.map +1 -1
- package/dist/native/rsc/server/request-context.js +10 -4
- package/dist/native/rsc/server/request-context.js.map +1 -1
- package/dist/native/rsc/server/route-element-builder.js +25 -7
- package/dist/native/rsc/server/route-element-builder.js.map +1 -1
- package/dist/native/rsc/server/route-module-loader.js +14 -6
- package/dist/native/rsc/server/route-module-loader.js.map +1 -1
- package/dist/native/rsc/server/rsc-cache-key-guard.js +5 -1
- package/dist/native/rsc/server/rsc-cache-key-guard.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +8 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +8 -1
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js.map +1 -1
- package/dist/native/rsc/server/segment-hash/outlet.js +28 -8
- package/dist/native/rsc/server/segment-hash/outlet.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/document-outlet.js +24 -0
- package/dist/native/rsc/server/segment-lifetime/document-outlet.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/key-digest.js +74 -0
- package/dist/native/rsc/server/segment-lifetime/key-digest.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/read-rule.js +56 -0
- package/dist/native/rsc/server/segment-lifetime/read-rule.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/read-scope.js +40 -0
- package/dist/native/rsc/server/segment-lifetime/read-scope.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/segment-key.js +50 -0
- package/dist/native/rsc/server/segment-lifetime/segment-key.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js +72 -0
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js.map +1 -0
- package/dist/native/rsc/server/slot-resolver.js +50 -26
- package/dist/native/rsc/server/slot-resolver.js.map +1 -1
- package/dist/native/rsc/server/slot-subtree-contain.js +17 -89
- package/dist/native/rsc/server/slot-subtree-contain.js.map +1 -1
- package/dist/native/rsc/server/subtree-walk.js +140 -0
- package/dist/native/rsc/server/subtree-walk.js.map +1 -0
- package/dist/native/rsc/shared/als-slots.js +2 -2
- package/dist/native/rsc/shared/als-slots.js.map +1 -1
- package/dist/native/rsc/shared/cookie-read-through.js +5 -0
- package/dist/native/rsc/shared/cookie-read-through.js.map +1 -0
- package/dist/native/rsc/shared/outlet-decision.js.map +1 -1
- package/dist/native/rsc/shared/route-options-export.js +8 -0
- package/dist/native/rsc/shared/route-options-export.js.map +1 -0
- package/dist/native/rsc/shared/rsc-cache-key.js +19 -3
- package/dist/native/rsc/shared/rsc-cache-key.js.map +1 -1
- package/dist/native/rsc/shims/headers.js +3 -4
- package/dist/native/rsc/shims/headers.js.map +1 -1
- package/dist/native/ssr/client/outlet-content-cache.js +17 -3
- package/dist/native/ssr/client/outlet-content-cache.js.map +1 -1
- package/dist/native/ssr/client/segment-outlet.js +3 -3
- package/dist/native/ssr/client/segment-outlet.js.map +1 -1
- package/dist/native/ssr/cookies/define-cookie.js +6 -2
- package/dist/native/ssr/cookies/define-cookie.js.map +1 -1
- package/dist/native/ssr/manifest.json +4 -0
- package/dist/native/ssr/search-params/define.js +4 -1
- package/dist/native/ssr/search-params/define.js.map +1 -1
- package/dist/native/ssr/server/als-registry.js +2 -1
- package/dist/native/ssr/server/als-registry.js.map +1 -1
- package/dist/native/ssr/server/client-state-tree.js +14 -9
- package/dist/native/ssr/server/client-state-tree.js.map +1 -1
- package/dist/native/ssr/server/cookie-context.js +12 -0
- package/dist/native/ssr/server/cookie-context.js.map +1 -1
- package/dist/native/ssr/server/flight-source.js +1 -0
- package/dist/native/ssr/server/flight-source.js.map +1 -1
- package/dist/native/ssr/server/framework-stack-frames.js +18 -0
- package/dist/native/ssr/server/framework-stack-frames.js.map +1 -0
- package/dist/native/ssr/server/request-context.js +10 -4
- package/dist/native/ssr/server/request-context.js.map +1 -1
- package/dist/native/ssr/server/rsc-cache-key-guard.js +5 -1
- package/dist/native/ssr/server/rsc-cache-key-guard.js.map +1 -1
- package/dist/native/ssr/server/segment-lifetime/key-digest.js +6 -0
- package/dist/native/ssr/server/segment-lifetime/key-digest.js.map +1 -0
- package/dist/native/ssr/server/segment-lifetime/read-rule.js +56 -0
- package/dist/native/ssr/server/segment-lifetime/read-rule.js.map +1 -0
- package/dist/native/ssr/shared/als-slots.js +2 -2
- package/dist/native/ssr/shared/als-slots.js.map +1 -1
- package/dist/native/ssr/shared/cookie-read-through.js +5 -0
- package/dist/native/ssr/shared/cookie-read-through.js.map +1 -0
- package/dist/native/ssr/shared/rsc-cache-key.js +19 -3
- package/dist/native/ssr/shared/rsc-cache-key.js.map +1 -1
- package/dist/native/ssr/shims/headers.js +3 -4
- package/dist/native/ssr/shims/headers.js.map +1 -1
- package/dist/plugins/callsite-jsx.d.ts +8 -1
- package/dist/plugins/callsite-jsx.d.ts.map +1 -1
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/prerender-sugar.d.ts +9 -8
- package/dist/plugins/prerender-sugar.d.ts.map +1 -1
- package/dist/plugins/routing.d.ts.map +1 -1
- package/dist/routing/convention-lint.d.ts +11 -3
- package/dist/routing/convention-lint.d.ts.map +1 -1
- package/dist/routing/export-detect.d.ts +50 -23
- package/dist/routing/export-detect.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/routing/route-options-lint.d.ts +36 -0
- package/dist/routing/route-options-lint.d.ts.map +1 -0
- package/dist/routing/route-options.d.ts +55 -0
- package/dist/routing/route-options.d.ts.map +1 -0
- package/dist/routing/segment-keys.d.ts +35 -0
- package/dist/routing/segment-keys.d.ts.map +1 -1
- package/dist/search-params/index.js +5 -2
- package/dist/search-params/index.js.map +1 -1
- package/dist/server/als-registry.d.ts +23 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/client-state-tree.d.ts +10 -3
- package/dist/server/client-state-tree.d.ts.map +1 -1
- package/dist/server/cookie-context.d.ts +3 -0
- package/dist/server/cookie-context.d.ts.map +1 -1
- package/dist/server/flight-source.d.ts +4 -1
- package/dist/server/flight-source.d.ts.map +1 -1
- package/dist/server/framework-stack-frames.d.ts +23 -0
- package/dist/server/framework-stack-frames.d.ts.map +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +105 -21
- package/dist/server/internal.js.map +1 -1
- package/dist/server/prebuilt/capture-routes.d.ts +1 -1
- package/dist/server/prebuilt-builder.d.ts.map +1 -1
- package/dist/server/request-context.d.ts +6 -1
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-module-loader.d.ts +10 -2
- package/dist/server/route-module-loader.d.ts.map +1 -1
- package/dist/server/rsc-cache-key-guard.d.ts +3 -1
- package/dist/server/rsc-cache-key-guard.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 +10 -0
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/revalidate-renderer.d.ts +12 -0
- package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
- package/dist/server/segment-hash/outlet.d.ts +28 -0
- package/dist/server/segment-hash/outlet.d.ts.map +1 -1
- package/dist/server/segment-lifetime/document-outlet.d.ts +66 -0
- package/dist/server/segment-lifetime/document-outlet.d.ts.map +1 -0
- package/dist/server/segment-lifetime/key-digest.d.ts +46 -0
- package/dist/server/segment-lifetime/key-digest.d.ts.map +1 -0
- package/dist/server/segment-lifetime/read-rule.d.ts +43 -0
- package/dist/server/segment-lifetime/read-rule.d.ts.map +1 -0
- package/dist/server/segment-lifetime/read-scope.d.ts +39 -0
- package/dist/server/segment-lifetime/read-scope.d.ts.map +1 -0
- package/dist/server/segment-lifetime/segment-key.d.ts +60 -0
- package/dist/server/segment-lifetime/segment-key.d.ts.map +1 -0
- package/dist/server/segment-lifetime/slot-outlets.d.ts +81 -0
- package/dist/server/segment-lifetime/slot-outlets.d.ts.map +1 -0
- package/dist/server/slot-resolver.d.ts +6 -1
- package/dist/server/slot-resolver.d.ts.map +1 -1
- package/dist/server/slot-subtree-contain.d.ts +2 -6
- package/dist/server/slot-subtree-contain.d.ts.map +1 -1
- package/dist/server/subtree-walk.d.ts +56 -0
- package/dist/server/subtree-walk.d.ts.map +1 -0
- package/dist/server/types.d.ts +69 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/als-slots.d.ts +12 -2
- package/dist/shared/als-slots.d.ts.map +1 -1
- package/dist/shared/cookie-read-through.d.ts +18 -0
- package/dist/shared/cookie-read-through.d.ts.map +1 -0
- package/dist/shared/outlet-decision.d.ts +23 -4
- package/dist/shared/outlet-decision.d.ts.map +1 -1
- package/dist/shared/route-options-export.d.ts +13 -0
- package/dist/shared/route-options-export.d.ts.map +1 -0
- package/dist/shared/rsc-cache-key.d.ts +22 -0
- package/dist/shared/rsc-cache-key.d.ts.map +1 -1
- package/dist/shared/segment-info.d.ts +6 -0
- package/dist/shared/segment-info.d.ts.map +1 -1
- package/dist/shims/headers.d.ts.map +1 -1
- package/docs/api/30-api-server.mdx +29 -0
- package/docs/api/32-api-cache.mdx +10 -4
- package/docs/api/34-api-config.mdx +5 -0
- package/docs/learn/09-streaming.mdx +6 -2
- package/docs/learn/10-caching.mdx +10 -4
- package/package.json +1 -1
- package/src/cli-check.ts +11 -3
- package/src/client/navigation-commit.ts +11 -2
- package/src/client/outlet-content-cache.ts +40 -8
- package/src/client/router.ts +1 -0
- package/src/client/segment-outlet.tsx +10 -4
- package/src/config-types.ts +25 -0
- package/src/config-validation.ts +17 -0
- package/src/cookies/define-cookie.ts +5 -1
- package/src/index.ts +2 -1
- package/src/plugins/callsite-jsx.ts +104 -6
- package/src/plugins/entries.ts +3 -0
- package/src/plugins/prerender-sugar.ts +34 -18
- package/src/plugins/routing.ts +3 -1
- package/src/routing/convention-lint.ts +18 -7
- package/src/routing/export-detect.ts +14 -117
- package/src/routing/route-options-lint.ts +153 -0
- package/src/routing/route-options.ts +423 -0
- package/src/routing/segment-keys.ts +50 -0
- package/src/rsc-runtime/vendor-types.d.ts +4 -0
- package/src/search-params/define.ts +1 -1
- package/src/server/als-registry.ts +29 -0
- package/src/server/client-state-tree.ts +30 -16
- package/src/server/cookie-context.ts +17 -0
- package/src/server/flight-source.ts +7 -1
- package/src/server/framework-stack-frames.ts +44 -0
- package/src/server/index.ts +7 -0
- package/src/server/prebuilt/capture-routes.ts +1 -1
- package/src/server/prebuilt-builder.ts +30 -2
- package/src/server/request-context.ts +28 -4
- package/src/server/route-element-builder.ts +80 -5
- package/src/server/route-module-loader.ts +43 -10
- package/src/server/rsc-cache-key-guard.ts +17 -2
- package/src/server/rsc-entry/index.ts +16 -0
- package/src/server/rsc-entry/render-route.ts +19 -1
- package/src/server/rsc-entry/revalidate-renderer.ts +17 -1
- package/src/server/segment-hash/outlet.ts +62 -18
- package/src/server/segment-lifetime/document-outlet.ts +98 -0
- package/src/server/segment-lifetime/key-digest.ts +139 -0
- package/src/server/segment-lifetime/read-rule.ts +136 -0
- package/src/server/segment-lifetime/read-scope.ts +99 -0
- package/src/server/segment-lifetime/segment-key.ts +140 -0
- package/src/server/segment-lifetime/slot-outlets.ts +180 -0
- package/src/server/slot-resolver.ts +99 -56
- package/src/server/slot-subtree-contain.ts +35 -182
- package/src/server/subtree-walk.ts +316 -0
- package/src/server/types.ts +85 -0
- package/src/shared/als-slots.ts +19 -8
- package/src/shared/cookie-read-through.ts +18 -0
- package/src/shared/outlet-decision.ts +25 -4
- package/src/shared/route-options-export.ts +14 -0
- package/src/shared/rsc-cache-key.ts +41 -2
- package/src/shared/segment-info.ts +6 -0
- package/src/shims/headers.ts +5 -4
- package/dist/_chunks/actions-DIgnvDrG.js.map +0 -1
- package/dist/_chunks/als-slots-kbQrHTzm.js.map +0 -1
- package/dist/_chunks/chains-CSslTUdI.js +0 -1
- package/dist/_chunks/cli-check-C3QOAru7.js.map +0 -1
- package/dist/_chunks/convention-lint-BoVISNS6.js.map +0 -1
- package/dist/_chunks/dev-server-B8roKA3Q.js +0 -1
- package/dist/_chunks/dev-server-C5R6jx8Q.js.map +0 -1
- package/dist/_chunks/dist-C1Rjlo6s.js.map +0 -1
- package/dist/_chunks/error-boundary-DB51f9ih.js.map +0 -1
- package/dist/_chunks/scanner-C9Lrf77z.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read rule of a `'document'` segment: it may read the request inputs in
|
|
3
|
+
* its key, and nothing else from the request (design/53-segment-lifetime.md
|
|
4
|
+
* §"What a 'document' segment may read").
|
|
5
|
+
*
|
|
6
|
+
* A `'document'` segment is skipped without rendering whenever its key is
|
|
7
|
+
* unchanged, so anything else it read would freeze silently at its load-time
|
|
8
|
+
* value. The rule makes that a thrown error instead, in every environment:
|
|
9
|
+
*
|
|
10
|
+
* - `getSegmentParams()` returns a view that throws on a param outside the key;
|
|
11
|
+
* - a search-params definition's `.get()` throws unless every field it reads is
|
|
12
|
+
* in the key's definition, and the raw search params throw;
|
|
13
|
+
* - the cookie jar throws on a cookie outside the key, and on `getAll()`;
|
|
14
|
+
* - the request headers throw — and with them the pathname, which no timber
|
|
15
|
+
* API exposes to a component except through a header.
|
|
16
|
+
*
|
|
17
|
+
* **Reach.** The scope is an AsyncLocalStorage scope around the segment's
|
|
18
|
+
* component, so it covers the component and everything it calls or awaits.
|
|
19
|
+
* That alone would not reach the server components it *returns*: Flight
|
|
20
|
+
* renders those later, as tasks of its own, outside the scope. So the
|
|
21
|
+
* returned tree is rewritten (`subtree-walk.ts`) and each server component in
|
|
22
|
+
* it runs inside the scope too, down to the nested outlets — a layout's
|
|
23
|
+
* `children` and slots, which are other segments with their own rules.
|
|
24
|
+
*
|
|
25
|
+
* Not covered: values computed outside this render and handed to it — a
|
|
26
|
+
* `timber.cache` entry an earlier request filled, or a module-level value. The
|
|
27
|
+
* accessors' checks are `read-rule.ts`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { createElement, type ReactNode } from 'react';
|
|
31
|
+
|
|
32
|
+
import { documentReadScopeAls, type DocumentReadScope } from '../als-registry.ts';
|
|
33
|
+
import { isOutletGateElement } from '../segment-hash/outlet.ts';
|
|
34
|
+
import { callAndRewrite, type ServerComponent, type SubtreeRule } from '../subtree-walk.ts';
|
|
35
|
+
import type { DocumentLifetime } from './segment-key.ts';
|
|
36
|
+
|
|
37
|
+
/** The read scope of one `'document'` segment. */
|
|
38
|
+
export function readScopeFor(
|
|
39
|
+
segmentPath: string,
|
|
40
|
+
lifetime: DocumentLifetime,
|
|
41
|
+
pathParams: readonly string[]
|
|
42
|
+
): DocumentReadScope {
|
|
43
|
+
const { key } = lifetime;
|
|
44
|
+
return {
|
|
45
|
+
segmentPath,
|
|
46
|
+
params: new Set(key.segmentParams ?? pathParams),
|
|
47
|
+
searchParams: new Map(
|
|
48
|
+
Object.entries(key.searchParams?.codecs ?? {}).map(([field, codec]) => [
|
|
49
|
+
field,
|
|
50
|
+
{ codec, urlKey: key.searchParams?.urlKeys[field] ?? field },
|
|
51
|
+
])
|
|
52
|
+
),
|
|
53
|
+
cookies: new Map((key.cookies ?? []).map((cookie) => [cookie.name, cookie.codec])),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The segment's component, run inside its read scope with every server
|
|
59
|
+
* component it returns rewritten to run there too.
|
|
60
|
+
*/
|
|
61
|
+
export function inReadScope(component: ServerComponent, scope: DocumentReadScope): ServerComponent {
|
|
62
|
+
const rule = scopeRule(scope);
|
|
63
|
+
return (props) => documentReadScopeAls.run(scope, () => callAndRewrite(component, props, rule));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Runs one server component from a scoped tree inside the scope. Declared at
|
|
68
|
+
* module scope and given the component as a prop, so its identity is stable
|
|
69
|
+
* across renders; `component` and `scope` are consumed here and never reach
|
|
70
|
+
* the Flight stream.
|
|
71
|
+
*/
|
|
72
|
+
function ScopedServerComponent(props: {
|
|
73
|
+
component: ServerComponent;
|
|
74
|
+
componentProps: Record<string, unknown>;
|
|
75
|
+
scope: DocumentReadScope;
|
|
76
|
+
}): ReactNode | Promise<ReactNode> {
|
|
77
|
+
const { component, componentProps, scope } = props;
|
|
78
|
+
return documentReadScopeAls.run(scope, () =>
|
|
79
|
+
callAndRewrite(component, componentProps, scopeRule(scope))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function scopeRule(scope: DocumentReadScope): SubtreeRule {
|
|
84
|
+
return {
|
|
85
|
+
wrap: (component, componentProps, key) =>
|
|
86
|
+
component === (ScopedServerComponent as unknown)
|
|
87
|
+
? undefined
|
|
88
|
+
: createElement(ScopedServerComponent, {
|
|
89
|
+
component,
|
|
90
|
+
componentProps,
|
|
91
|
+
scope,
|
|
92
|
+
...(key !== null ? { key } : undefined),
|
|
93
|
+
}),
|
|
94
|
+
// A nested outlet is another segment: its own lifetime decides what it reads.
|
|
95
|
+
isOpaque: isOutletGateElement,
|
|
96
|
+
// An async iterable it returned reads, as it is advanced, inside the scope.
|
|
97
|
+
runIn: (fn) => documentReadScopeAls.run(scope, fn),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A segment's lifetime, read from its loaded module, and the parsed values of
|
|
3
|
+
* the request inputs in its key.
|
|
4
|
+
*
|
|
5
|
+
* Design doc: design/53-segment-lifetime.md §"Segment keys".
|
|
6
|
+
*
|
|
7
|
+
* The values are one canonical string per segment, the input the key digest
|
|
8
|
+
* MACs (`key-digest.ts`). Each part is compared after parsing, through the
|
|
9
|
+
* definition that owns it, so two requests that differ only in a way the
|
|
10
|
+
* segment cannot observe produce the same string:
|
|
11
|
+
*
|
|
12
|
+
* - **segment params** — the coerced params (each segment's codec applied);
|
|
13
|
+
* - **search params** — `def.buildSearchParams(def.parse(…))`, which applies
|
|
14
|
+
* defaults, aliases (`withUrlKey`) and drops values that parse to the default;
|
|
15
|
+
* - **cookies** — `codec.serialize(codec.parse(raw))` per definition. The raw
|
|
16
|
+
* value comes from the request's cookie jar, which reflects cookies the
|
|
17
|
+
* current server action set (design/53 open question 4), so an action's
|
|
18
|
+
* revalidated render issues digests from the values the browser will send
|
|
19
|
+
* next.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { CoercedParams } from '../../shared/param-value.ts';
|
|
23
|
+
import { ROUTE_OPTIONS_EXPORT, type RouteOptionsKind } from '../../shared/route-options-export.ts';
|
|
24
|
+
import { getCookieJar } from '../cookie-context.ts';
|
|
25
|
+
import { getSearchParams } from '../request-context.ts';
|
|
26
|
+
import type { SegmentKey, SegmentLifetime } from '../types.ts';
|
|
27
|
+
|
|
28
|
+
/** A segment declared `lifetime: 'document'`, with the key it declared (if any). */
|
|
29
|
+
export interface DocumentLifetime {
|
|
30
|
+
key: SegmentKey;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The lifetime of a layout that declares none, at the end of `chain` (the
|
|
35
|
+
* segments from the root down to it, slot chains included): the app's
|
|
36
|
+
* `defaultLayoutLifetime`, except at or below an intercepting segment.
|
|
37
|
+
* Options there are a build error (`routing/route-options-lint.ts`), so a
|
|
38
|
+
* defaulted layout under an intercepting directory could never opt back to
|
|
39
|
+
* `'request'` — it keeps `'request'` instead (design/53 §"App-wide default").
|
|
40
|
+
* A page always defaults to `'request'`.
|
|
41
|
+
*/
|
|
42
|
+
export function defaultLayoutLifetimeAt(
|
|
43
|
+
chain: readonly { segmentType?: string }[],
|
|
44
|
+
appDefault: SegmentLifetime
|
|
45
|
+
): SegmentLifetime {
|
|
46
|
+
return chain.some((segment) => segment.segmentType === 'intercepting') ? 'request' : appDefault;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The module's lifetime: a `DocumentLifetime` when its options object
|
|
51
|
+
* declares `lifetime: 'document'`, or declares no lifetime and
|
|
52
|
+
* `defaultLifetime` is `'document'`; undefined otherwise. The build validated
|
|
53
|
+
* the object from source (`routing/route-options.ts`); this runtime read is
|
|
54
|
+
* what takes effect.
|
|
55
|
+
*
|
|
56
|
+
* @param defaultLifetime The lifetime of a module that declares none: the
|
|
57
|
+
* app's `defaultLayoutLifetime` for a layout, `'request'` for a page
|
|
58
|
+
* (design/53 §"App-wide default").
|
|
59
|
+
*/
|
|
60
|
+
export function readDocumentLifetime(
|
|
61
|
+
mod: Record<string, unknown>,
|
|
62
|
+
kind: RouteOptionsKind,
|
|
63
|
+
defaultLifetime: SegmentLifetime
|
|
64
|
+
): DocumentLifetime | undefined {
|
|
65
|
+
const exported = mod[ROUTE_OPTIONS_EXPORT[kind]];
|
|
66
|
+
const options = typeof exported === 'object' && exported !== null ? exported : {};
|
|
67
|
+
const lifetime = 'lifetime' in options ? options.lifetime : undefined;
|
|
68
|
+
if ((lifetime ?? defaultLifetime) !== 'document') return undefined;
|
|
69
|
+
const key = 'key' in options ? options.key : undefined;
|
|
70
|
+
// The module's own export, typed `satisfies LayoutOptions` / `PageOptions`
|
|
71
|
+
// in source and shape-checked by the build; at runtime it is an `object`.
|
|
72
|
+
return { key: typeof key === 'object' && key !== null ? (key as SegmentKey) : {} };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The canonical key values of one segment in the current request.
|
|
77
|
+
*
|
|
78
|
+
* @param pathParams Every param name on the segment's path, outermost first —
|
|
79
|
+
* the default `segmentParams`.
|
|
80
|
+
* @param params The coerced values of those params.
|
|
81
|
+
*/
|
|
82
|
+
export function readKeyValues(
|
|
83
|
+
lifetime: DocumentLifetime,
|
|
84
|
+
pathParams: readonly string[],
|
|
85
|
+
params: CoercedParams
|
|
86
|
+
): string {
|
|
87
|
+
const { key } = lifetime;
|
|
88
|
+
const names = key.segmentParams ?? pathParams;
|
|
89
|
+
const segmentParams = names.map((name) => [name, canonicalParam(params[name])]);
|
|
90
|
+
|
|
91
|
+
const definition = key.searchParams;
|
|
92
|
+
const searchParams = definition
|
|
93
|
+
? definition.buildSearchParams(definition.parse(getSearchParams()))
|
|
94
|
+
: null;
|
|
95
|
+
|
|
96
|
+
const jar = key.cookies && key.cookies.length > 0 ? getCookieJar() : null;
|
|
97
|
+
const cookies = (key.cookies ?? []).map((cookie) => [
|
|
98
|
+
cookie.name,
|
|
99
|
+
cookie.codec.serialize(cookie.codec.parse(jar?.get(cookie.name))),
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
return JSON.stringify([segmentParams, searchParams, cookies]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A coerced param as a stable string that keeps every distinct value of the
|
|
107
|
+
* param domain (`shared/param-value.ts`) distinct. Every value is written as a
|
|
108
|
+
* tagged array, so no plain object can spell another kind's tag: `Map` and
|
|
109
|
+
* `Set` (which JSON writes as `{}`), `NaN` and `±Infinity` (which it writes
|
|
110
|
+
* as `null`), `-0`, `bigint`, `undefined` and `Date` each get their own.
|
|
111
|
+
* A `Map` and a plain object keep their insertion order, as a reader sees it.
|
|
112
|
+
*/
|
|
113
|
+
function canonicalParam(value: unknown): string {
|
|
114
|
+
return JSON.stringify(tagged(value));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function tagged(value: unknown): unknown {
|
|
118
|
+
if (value === undefined) return ['u'];
|
|
119
|
+
if (value === null) return ['n'];
|
|
120
|
+
switch (typeof value) {
|
|
121
|
+
case 'string':
|
|
122
|
+
return ['s', value];
|
|
123
|
+
case 'boolean':
|
|
124
|
+
return ['b', value];
|
|
125
|
+
case 'bigint':
|
|
126
|
+
return ['i', value.toString()];
|
|
127
|
+
case 'number':
|
|
128
|
+
return ['f', Object.is(value, -0) ? '-0' : String(value)];
|
|
129
|
+
case 'object':
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
return ['?', String(value)];
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(value)) return ['a', value.map(tagged)];
|
|
135
|
+
if (value instanceof Date)
|
|
136
|
+
return ['d', Number.isNaN(value.getTime()) ? 'invalid' : value.toISOString()];
|
|
137
|
+
if (value instanceof Map) return ['m', [...value].map(([k, v]) => [tagged(k), tagged(v)])];
|
|
138
|
+
if (value instanceof Set) return ['t', [...value].map(tagged)];
|
|
139
|
+
return ['o', Object.entries(value).map(([k, v]) => [k, tagged(v)])];
|
|
140
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outlets for `'document'` segments inside a parallel slot.
|
|
3
|
+
*
|
|
4
|
+
* A slot is one outlet (`<owner>/@<slot>`); the layouts and page on its
|
|
5
|
+
* matched chain render inside it with no outlets of their own. A `'document'`
|
|
6
|
+
* segment needs one, so it can be skipped while the rest of the slot is
|
|
7
|
+
* decided independently (design/53-segment-lifetime.md §"Slots"):
|
|
8
|
+
*
|
|
9
|
+
* - a `'document'` **page** gets `pageOutletKey(<tree path>)`;
|
|
10
|
+
* - a `'document'` **layout** gets `layoutOutletKey(<tree path>)`, and
|
|
11
|
+
* what it receives as `children` becomes that key's `children` outlet —
|
|
12
|
+
* the same split as a main-chain layout, so skipping the layout's chrome
|
|
13
|
+
* never freezes what renders under it.
|
|
14
|
+
*
|
|
15
|
+
* A segment's identity is its tree path, which includes the `@slot`
|
|
16
|
+
* directory, so two slots never share an entry, and a slot rendering its
|
|
17
|
+
* `default.tsx` (which takes no options) has no `'document'` outlet at all.
|
|
18
|
+
*
|
|
19
|
+
* The outlets are created whether or not the render can issue digests, so a
|
|
20
|
+
* route's element structure is the same on every request.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { ReactElement } from 'react';
|
|
24
|
+
import {
|
|
25
|
+
childrenOutletKey,
|
|
26
|
+
pageOutletKey,
|
|
27
|
+
slotChainTreePath,
|
|
28
|
+
layoutOutletKey,
|
|
29
|
+
} from '../../routing/segment-keys.ts';
|
|
30
|
+
import type { CoercedParams } from '../../shared/param-value.ts';
|
|
31
|
+
import type { ManifestSegmentNode } from '../route-matcher.ts';
|
|
32
|
+
import { outletGate, type OutletSpec, type SegmentHashRender } from '../segment-hash/outlet.ts';
|
|
33
|
+
import { documentOutletFor } from './document-outlet.ts';
|
|
34
|
+
import {
|
|
35
|
+
defaultLayoutLifetimeAt,
|
|
36
|
+
readDocumentLifetime,
|
|
37
|
+
type DocumentLifetime,
|
|
38
|
+
} from './segment-key.ts';
|
|
39
|
+
import { inReadScope, readScopeFor } from './read-scope.ts';
|
|
40
|
+
import type { ServerComponent } from '../subtree-walk.ts';
|
|
41
|
+
|
|
42
|
+
/** Everything a slot's `'document'` outlets need from the slot being resolved. */
|
|
43
|
+
export interface SlotDocumentContext {
|
|
44
|
+
render: SegmentHashRender;
|
|
45
|
+
/** The slot's matched chain, slot root first. */
|
|
46
|
+
chain: readonly ManifestSegmentNode[];
|
|
47
|
+
/** The tree path of the segment that owns the slot. */
|
|
48
|
+
parentTreePath: string;
|
|
49
|
+
/** Param names on the path above the slot, outermost first. */
|
|
50
|
+
ownerParams: readonly string[];
|
|
51
|
+
/** The main-chain segments from the root down to the slot's owner. */
|
|
52
|
+
ownerChain: readonly ManifestSegmentNode[];
|
|
53
|
+
/**
|
|
54
|
+
* The main route's coerced params with the slot's own over them. Read only
|
|
55
|
+
* when a 'document' segment is decided.
|
|
56
|
+
*/
|
|
57
|
+
params: () => CoercedParams;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Builds a slot's `'document'` outlets from the leaf outward, and reports the
|
|
62
|
+
* outermost of them: the slot's own outlet holds those directly, and a skip
|
|
63
|
+
* of it must carry their decisions.
|
|
64
|
+
*/
|
|
65
|
+
export class SlotDocumentOutlets {
|
|
66
|
+
private unclaimed: OutletSpec[] = [];
|
|
67
|
+
|
|
68
|
+
constructor(private readonly ctx: SlotDocumentContext) {}
|
|
69
|
+
|
|
70
|
+
/** The outlets built so far that no outlet built so far contains. */
|
|
71
|
+
outermost(): OutletSpec[] {
|
|
72
|
+
return this.unclaimed;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A slot segment's lifetime: its own declaration, else the app's
|
|
77
|
+
* `defaultLayoutLifetime` for a layout (`defaultLayoutLifetimeAt`) and
|
|
78
|
+
* `'request'` for a page.
|
|
79
|
+
*/
|
|
80
|
+
lifetimeOf(
|
|
81
|
+
node: ManifestSegmentNode,
|
|
82
|
+
mod: Record<string, unknown>,
|
|
83
|
+
kind: 'page' | 'layout'
|
|
84
|
+
): DocumentLifetime | undefined {
|
|
85
|
+
if (kind === 'page') return readDocumentLifetime(mod, kind, 'request');
|
|
86
|
+
const chain = [...this.ctx.ownerChain, ...this.ctx.chain.slice(0, this.depth(node) + 1)];
|
|
87
|
+
const fallback = defaultLayoutLifetimeAt(chain, this.ctx.render.defaultLayoutLifetime);
|
|
88
|
+
return readDocumentLifetime(mod, kind, fallback);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Wrap a `'document'` slot page in its own outlet. */
|
|
92
|
+
async page(
|
|
93
|
+
node: ManifestSegmentNode,
|
|
94
|
+
lifetime: DocumentLifetime,
|
|
95
|
+
element: ReactElement
|
|
96
|
+
): Promise<ReactElement> {
|
|
97
|
+
const segmentPath = pageOutletKey(this.treePath(node));
|
|
98
|
+
const spec: OutletSpec = {
|
|
99
|
+
segmentPath,
|
|
100
|
+
content: element,
|
|
101
|
+
nested: this.unclaimed,
|
|
102
|
+
document: await this.decision(node, segmentPath, lifetime),
|
|
103
|
+
};
|
|
104
|
+
this.unclaimed = [spec];
|
|
105
|
+
return outletGate(spec, this.ctx.render);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Wrap a `'document'` slot layout: its `children` in one outlet and the
|
|
110
|
+
* layout built around that outlet in another.
|
|
111
|
+
*/
|
|
112
|
+
async layout(
|
|
113
|
+
node: ManifestSegmentNode,
|
|
114
|
+
lifetime: DocumentLifetime,
|
|
115
|
+
children: ReactElement,
|
|
116
|
+
buildLayout: (children: ReactElement) => ReactElement
|
|
117
|
+
): Promise<ReactElement> {
|
|
118
|
+
const segmentPath = layoutOutletKey(this.treePath(node));
|
|
119
|
+
const childrenOutlet: OutletSpec = {
|
|
120
|
+
segmentPath: childrenOutletKey(segmentPath),
|
|
121
|
+
content: children,
|
|
122
|
+
nested: this.unclaimed,
|
|
123
|
+
};
|
|
124
|
+
const spec: OutletSpec = {
|
|
125
|
+
segmentPath,
|
|
126
|
+
content: buildLayout(outletGate(childrenOutlet, this.ctx.render)),
|
|
127
|
+
nested: [childrenOutlet],
|
|
128
|
+
document: await this.decision(node, segmentPath, lifetime),
|
|
129
|
+
};
|
|
130
|
+
this.unclaimed = [spec];
|
|
131
|
+
return outletGate(spec, this.ctx.render);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A 'document' slot segment's component, run in its read scope
|
|
136
|
+
* (`read-scope.ts`): a read outside its key throws.
|
|
137
|
+
*/
|
|
138
|
+
scoped(
|
|
139
|
+
node: ManifestSegmentNode,
|
|
140
|
+
kind: 'page' | 'layout',
|
|
141
|
+
lifetime: DocumentLifetime,
|
|
142
|
+
component: ServerComponent
|
|
143
|
+
): ServerComponent {
|
|
144
|
+
const treePath = this.treePath(node);
|
|
145
|
+
const segmentPath = kind === 'page' ? pageOutletKey(treePath) : layoutOutletKey(treePath);
|
|
146
|
+
return inReadScope(component, readScopeFor(segmentPath, lifetime, this.pathParams(node)));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private decision(node: ManifestSegmentNode, segmentPath: string, lifetime: DocumentLifetime) {
|
|
150
|
+
return documentOutletFor(
|
|
151
|
+
this.ctx.render,
|
|
152
|
+
segmentPath,
|
|
153
|
+
lifetime,
|
|
154
|
+
this.pathParams(node),
|
|
155
|
+
this.ctx.params()
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Every param on the node's path: the owner's, then the slot chain's down to it. */
|
|
160
|
+
private pathParams(node: ManifestSegmentNode): string[] {
|
|
161
|
+
const slotParams = this.ctx.chain
|
|
162
|
+
.slice(0, this.depth(node) + 1)
|
|
163
|
+
.flatMap((n) => (n.paramName ? [n.paramName] : []));
|
|
164
|
+
return [...this.ctx.ownerParams, ...slotParams];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The node's full tree path: the owner's, then each chain directory down to it. */
|
|
168
|
+
private treePath(node: ManifestSegmentNode): string {
|
|
169
|
+
return slotChainTreePath(
|
|
170
|
+
this.ctx.chain.slice(0, this.depth(node) + 1),
|
|
171
|
+
this.ctx.parentTreePath
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private depth(node: ManifestSegmentNode): number {
|
|
176
|
+
const depth = this.ctx.chain.indexOf(node);
|
|
177
|
+
if (depth === -1) throw new Error(`[timber] ${node.segmentName} is not on the slot's chain`);
|
|
178
|
+
return depth;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -32,8 +32,17 @@ import type { CoercedParams } from '../shared/param-value.ts';
|
|
|
32
32
|
import { matchUrlParts } from './tree-match.ts';
|
|
33
33
|
import { extractUrlParts } from './chain-url-parts.ts';
|
|
34
34
|
import { findInterceptingMatch } from './slot-interception.ts';
|
|
35
|
-
import { computeSlotKey } from '../routing/segment-keys.ts';
|
|
36
|
-
import {
|
|
35
|
+
import { computeSlotKey, slotChainTreePath } from '../routing/segment-keys.ts';
|
|
36
|
+
import {
|
|
37
|
+
NO_SEGMENT_HASHING,
|
|
38
|
+
outletGate,
|
|
39
|
+
type OutletSpec,
|
|
40
|
+
type SegmentHashRender,
|
|
41
|
+
} from './segment-hash/outlet.ts';
|
|
42
|
+
import { getSegmentParams } from './request-context.ts';
|
|
43
|
+
import { pathParamNames } from './segment-lifetime/document-outlet.ts';
|
|
44
|
+
import { SlotDocumentOutlets } from './segment-lifetime/slot-outlets.ts';
|
|
45
|
+
import type { ServerComponent } from './subtree-walk.ts';
|
|
37
46
|
import { clientComponents } from './vite-handoff-rsc.ts';
|
|
38
47
|
|
|
39
48
|
type CreateElementFn = (...args: unknown[]) => React.ReactElement;
|
|
@@ -87,16 +96,17 @@ export async function resolveSlotElement(
|
|
|
87
96
|
h: CreateElementFn,
|
|
88
97
|
req: Request,
|
|
89
98
|
interception?: InterceptionContext,
|
|
90
|
-
parentTreePath?: string
|
|
91
|
-
|
|
99
|
+
parentTreePath?: string,
|
|
100
|
+
render: SegmentHashRender = NO_SEGMENT_HASHING
|
|
101
|
+
): Promise<ResolvedSlotElement> {
|
|
92
102
|
// When interception is active, try to match intercepting children in this
|
|
93
103
|
// slot against the target pathname. If an intercepting child matches, render
|
|
94
104
|
// it instead of the normal slot match. This enables the modal pattern:
|
|
95
105
|
// the slot shows the intercepted content on soft navigation.
|
|
96
|
-
const
|
|
97
|
-
?
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
const intercepting = interception
|
|
107
|
+
? findInterceptingMatch(slotNode, interception.targetPathname)
|
|
108
|
+
: null;
|
|
109
|
+
const slotMatch = intercepting ?? findSlotMatch(slotNode, match);
|
|
100
110
|
|
|
101
111
|
if (slotMatch) {
|
|
102
112
|
// Coerce the slot's own chain params through the global schema codecs
|
|
@@ -114,14 +124,40 @@ export async function resolveSlotElement(
|
|
|
114
124
|
// Both derive from the same coerced record, so the keyed overload and the
|
|
115
125
|
// no-arg call inside the slot can never disagree.
|
|
116
126
|
const coerced = coerceSlotParams(slotMatch.chain, slotMatch.slotParams);
|
|
117
|
-
const fullSlotPath =
|
|
127
|
+
const fullSlotPath = parentTreePath
|
|
128
|
+
? slotChainTreePath(slotMatch.chain, parentTreePath)
|
|
129
|
+
: undefined;
|
|
118
130
|
|
|
119
131
|
if (fullSlotPath && Object.keys(coerced).length > 0) {
|
|
120
132
|
setSlotParams(fullSlotPath, coerced);
|
|
121
133
|
}
|
|
122
134
|
const scope = <T>(fn: () => T): T => runWithSlotSegmentParams(fullSlotPath, coerced, fn);
|
|
123
135
|
|
|
124
|
-
const
|
|
136
|
+
const ownerIndex = findSlotOwnerIndex(slotNode, match.segments);
|
|
137
|
+
// 'document' segments on the chain get outlets of their own (design/53
|
|
138
|
+
// §"Slots"). Not on an intercepting route, which takes no options and
|
|
139
|
+
// renders only on a soft navigation; not without a tree path to key by.
|
|
140
|
+
const documents =
|
|
141
|
+
parentTreePath && !intercepting
|
|
142
|
+
? new SlotDocumentOutlets({
|
|
143
|
+
render,
|
|
144
|
+
chain: slotMatch.chain,
|
|
145
|
+
parentTreePath,
|
|
146
|
+
ownerParams: pathParamNames(match.segments, ownerIndex),
|
|
147
|
+
ownerChain: match.segments.slice(0, ownerIndex + 1),
|
|
148
|
+
params: () => ({ ...getSegmentParams(), ...coerced }),
|
|
149
|
+
})
|
|
150
|
+
: undefined;
|
|
151
|
+
|
|
152
|
+
const pageModule = await loadModule(slotMatch.page);
|
|
153
|
+
const LoadedSlotPage = pageModule.default as ((...args: unknown[]) => unknown) | undefined;
|
|
154
|
+
const leafNode = slotMatch.chain[slotMatch.chain.length - 1];
|
|
155
|
+
const pageLifetime = documents && documents.lifetimeOf(leafNode, pageModule, 'page');
|
|
156
|
+
// A 'document' slot page runs in its read scope; a client page never runs here.
|
|
157
|
+
const SlotPage =
|
|
158
|
+
pageLifetime && LoadedSlotPage && !isClientReference(LoadedSlotPage)
|
|
159
|
+
? documents.scoped(leafNode, 'page', pageLifetime, LoadedSlotPage as ServerComponent)
|
|
160
|
+
: LoadedSlotPage;
|
|
125
161
|
if (SlotPage) {
|
|
126
162
|
// Load default.tsx fallback for notFound() handling in the slot page.
|
|
127
163
|
// When a slot page calls notFound() or deny(), it should gracefully
|
|
@@ -181,6 +217,10 @@ export async function resolveSlotElement(
|
|
|
181
217
|
element = h(SafeSlotPage, {});
|
|
182
218
|
}
|
|
183
219
|
|
|
220
|
+
// A 'document' slot page in its own outlet, inside its segment's access
|
|
221
|
+
// gate and boundaries (wrapped around it below).
|
|
222
|
+
if (pageLifetime) element = await documents.page(leafNode, pageLifetime, element);
|
|
223
|
+
|
|
184
224
|
// Wrap with error boundaries, layouts, and access gates from
|
|
185
225
|
// intermediate slot segments (everything between slot root and leaf).
|
|
186
226
|
// Process innermost-first, same order as route-element-builder.ts
|
|
@@ -192,12 +232,21 @@ export async function resolveSlotElement(
|
|
|
192
232
|
h,
|
|
193
233
|
req,
|
|
194
234
|
scope,
|
|
195
|
-
denyFallback
|
|
235
|
+
denyFallback,
|
|
236
|
+
documents
|
|
196
237
|
);
|
|
197
238
|
|
|
198
239
|
// Wrap with slot root's layout — INSIDE the access gate, so the layout
|
|
199
240
|
// server component never executes when access.ts denies. See TIM-1074.
|
|
200
|
-
element = await wrapWithLayout(
|
|
241
|
+
element = await wrapWithLayout(
|
|
242
|
+
slotNode,
|
|
243
|
+
slotNode,
|
|
244
|
+
element,
|
|
245
|
+
h,
|
|
246
|
+
scope,
|
|
247
|
+
denyFallback,
|
|
248
|
+
documents
|
|
249
|
+
);
|
|
201
250
|
|
|
202
251
|
// Wrap in SlotAccessGate if slot root has access.ts. The gate is
|
|
203
252
|
// OUTSIDE the layout, matching the segment model in
|
|
@@ -232,7 +281,7 @@ export async function resolveSlotElement(
|
|
|
232
281
|
children: element,
|
|
233
282
|
});
|
|
234
283
|
|
|
235
|
-
return element;
|
|
284
|
+
return { element, outlets: documents?.outermost() ?? [] };
|
|
236
285
|
}
|
|
237
286
|
}
|
|
238
287
|
|
|
@@ -240,34 +289,13 @@ export async function resolveSlotElement(
|
|
|
240
289
|
// Per design/02-rendering-pipeline.md: "No access check for default.tsx."
|
|
241
290
|
// Access verdicts from the eager evaluation are not applied here.
|
|
242
291
|
// Pass taintKey so accessor calls inside default.tsx are scoped to this
|
|
243
|
-
return renderDefaultFallback(slotNode, h);
|
|
292
|
+
return { element: await renderDefaultFallback(slotNode, h), outlets: [] };
|
|
244
293
|
}
|
|
245
294
|
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
* Built from the parent's tree path plus each chain node's directory name,
|
|
251
|
-
* so an intercepting node contributes its marker
|
|
252
|
-
* (`/gallery/@modal/(.)photo/[id]`) and a route group contributes its
|
|
253
|
-
* parentheses. Returns undefined when the caller has no parent tree path,
|
|
254
|
-
* which is how the resolver's test callers and any path-less entry point opt
|
|
255
|
-
* out of keyed lookups.
|
|
256
|
-
*
|
|
257
|
-
* One definition for both the render path and the eager access path: they
|
|
258
|
-
* key the same map, and a divergence would silently strand one of them.
|
|
259
|
-
*/
|
|
260
|
-
function computeSlotSegmentPath(
|
|
261
|
-
chain: ManifestSegmentNode[],
|
|
262
|
-
parentTreePath: string | undefined
|
|
263
|
-
): string | undefined {
|
|
264
|
-
if (!parentTreePath) return undefined;
|
|
265
|
-
const slotSuffix = chain
|
|
266
|
-
.map((s) => s.segmentName)
|
|
267
|
-
.filter(Boolean)
|
|
268
|
-
.join('/');
|
|
269
|
-
const prefix = parentTreePath === '/' ? '' : parentTreePath;
|
|
270
|
-
return `${prefix}/${slotSuffix}`;
|
|
295
|
+
/** A slot's content, and the outlets inside it that its own outlet holds directly. */
|
|
296
|
+
export interface ResolvedSlotElement {
|
|
297
|
+
element: React.ReactElement | null;
|
|
298
|
+
outlets: OutletSpec[];
|
|
271
299
|
}
|
|
272
300
|
|
|
273
301
|
// ─── Element Wrapping Helpers ───────────────────────────────────────────────
|
|
@@ -295,7 +323,8 @@ async function wrapWithIntermediateSegments(
|
|
|
295
323
|
h: CreateElementFn,
|
|
296
324
|
req: Request,
|
|
297
325
|
scope?: SlotParamScope,
|
|
298
|
-
denyFallback?: React.ReactNode
|
|
326
|
+
denyFallback?: React.ReactNode,
|
|
327
|
+
documents?: SlotDocumentOutlets
|
|
299
328
|
): Promise<React.ReactElement> {
|
|
300
329
|
for (let i = chain.length - 1; i > 0; i--) {
|
|
301
330
|
const seg = chain[i];
|
|
@@ -305,7 +334,7 @@ async function wrapWithIntermediateSegments(
|
|
|
305
334
|
errorBoundaryComponent: clientComponents().TimberErrorBoundary,
|
|
306
335
|
isSlotBoundary: true,
|
|
307
336
|
});
|
|
308
|
-
element = await wrapWithLayout(seg, slotNode, element, h, scope, denyFallback);
|
|
337
|
+
element = await wrapWithLayout(seg, slotNode, element, h, scope, denyFallback, documents);
|
|
309
338
|
element = await wrapWithAccessGate(seg, element, h, scope);
|
|
310
339
|
}
|
|
311
340
|
return element;
|
|
@@ -398,20 +427,33 @@ async function wrapWithLayout(
|
|
|
398
427
|
element: React.ReactElement,
|
|
399
428
|
h: CreateElementFn,
|
|
400
429
|
scope?: SlotParamScope,
|
|
401
|
-
denyFallback: React.ReactNode = null
|
|
430
|
+
denyFallback: React.ReactNode = null,
|
|
431
|
+
documents?: SlotDocumentOutlets
|
|
402
432
|
): Promise<React.ReactElement> {
|
|
403
433
|
if (!node.layout) return element;
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
if (!
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
434
|
+
const mod = await loadModule(node.layout);
|
|
435
|
+
const Loaded = mod.default as ((...args: unknown[]) => unknown) | undefined;
|
|
436
|
+
if (!Loaded) return element;
|
|
437
|
+
const lifetime = documents && documents.lifetimeOf(node, mod, 'layout');
|
|
438
|
+
// A 'document' slot layout runs in its read scope; a client layout never runs here.
|
|
439
|
+
const Layout =
|
|
440
|
+
lifetime && !isClientReference(Loaded)
|
|
441
|
+
? documents.scoped(node, 'layout', lifetime, Loaded as ServerComponent)
|
|
442
|
+
: Loaded;
|
|
443
|
+
const build = (children: React.ReactElement): React.ReactElement =>
|
|
444
|
+
!scope || isClientReference(Layout)
|
|
445
|
+
? h(Layout, { children })
|
|
446
|
+
: h(ScopedSlotLayout, {
|
|
447
|
+
layout: Layout as (props: Record<string, unknown>) => unknown,
|
|
448
|
+
scope,
|
|
449
|
+
denyFallback,
|
|
450
|
+
spanAttributes: slotSpanAttributes('timber.segment', node, slotNode),
|
|
451
|
+
children,
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// A 'document' slot layout: its chrome and its children in outlets of
|
|
455
|
+
// their own (segment-lifetime/slot-outlets.ts).
|
|
456
|
+
return lifetime ? documents.layout(node, lifetime, element, build) : build(element);
|
|
415
457
|
}
|
|
416
458
|
|
|
417
459
|
/**
|
|
@@ -572,18 +614,19 @@ export async function resolveSlotProps({
|
|
|
572
614
|
const outlets: OutletSpec[] = [];
|
|
573
615
|
|
|
574
616
|
for (const [slotName, slotNode] of Object.entries(segment.slots ?? {})) {
|
|
575
|
-
const content = await resolveSlotElement(
|
|
617
|
+
const { element: content, outlets: nested } = await resolveSlotElement(
|
|
576
618
|
slotNode as ManifestSegmentNode,
|
|
577
619
|
match,
|
|
578
620
|
h,
|
|
579
621
|
req,
|
|
580
622
|
interception,
|
|
581
|
-
parentTreePath
|
|
623
|
+
parentTreePath,
|
|
624
|
+
render
|
|
582
625
|
);
|
|
583
626
|
const spec: OutletSpec = {
|
|
584
627
|
segmentPath: computeSlotKey(segmentId, `@${slotName}`),
|
|
585
628
|
content,
|
|
586
|
-
nested
|
|
629
|
+
nested,
|
|
587
630
|
};
|
|
588
631
|
outlets.push(spec);
|
|
589
632
|
props[slotName] = outletGate(spec, render);
|