@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
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* timber-prerender-sugar — Vite plugin that desugars `
|
|
3
|
-
*
|
|
2
|
+
* timber-prerender-sugar — Vite plugin that desugars `prerender` in a page's
|
|
3
|
+
* `pageOptions` (or an ancestor layout's `layoutOptions`) into a
|
|
4
|
+
* `cache.component(...)` wrapper around the page.
|
|
4
5
|
*
|
|
5
6
|
* Design doc: design/45-cache-lifetimes.md §"Route-Level Static" and
|
|
6
|
-
* §"Layout Propagation".
|
|
7
|
+
* §"Layout Propagation"; design/53-segment-lifetime.md §"Route-module options".
|
|
7
8
|
*
|
|
8
|
-
* `
|
|
9
|
+
* `pageOptions = { prerender: true }` on a page is pure sugar: it desugars to
|
|
9
10
|
* wrapping the page's default export in `timber.cache.component(Component,
|
|
10
11
|
* { prerender: true })`. Layout propagation cascades a layout's
|
|
11
|
-
* `
|
|
12
|
+
* `layoutOptions.prerender` to descendant pages via most-specific-wins:
|
|
12
13
|
* walk the segment tree from leaf to root, first explicit value wins.
|
|
13
14
|
*
|
|
14
15
|
* Layout declarations are propagation policy only. Layouts receive the real
|
|
@@ -24,7 +25,8 @@ import MagicString from 'magic-string';
|
|
|
24
25
|
import type { Plugin } from 'vite';
|
|
25
26
|
import type { PluginContext } from '../plugin-context.ts';
|
|
26
27
|
import type { SegmentNode, RouteFile } from '../routing/types.ts';
|
|
27
|
-
import {
|
|
28
|
+
import type { RoutePrerender } from '../server/types.ts';
|
|
29
|
+
import { readRouteOptions } from '../routing/route-options.ts';
|
|
28
30
|
|
|
29
31
|
interface AstNode {
|
|
30
32
|
type: string;
|
|
@@ -40,25 +42,25 @@ interface AstNode {
|
|
|
40
42
|
* Walk the segment tree and resolve the effective prerender value for
|
|
41
43
|
* every page. Returns a map from page file path to resolved value.
|
|
42
44
|
*
|
|
43
|
-
* **Pages:** walk from leaf toward root; first explicit `
|
|
45
|
+
* **Pages:** walk from leaf toward root; first explicit `prerender` option
|
|
44
46
|
* wins (page > nearest layout > ... > root layout). If none, dynamic.
|
|
45
47
|
*
|
|
46
48
|
* **Layouts:** declarations propagate to descendant pages but layouts are not
|
|
47
49
|
* included in the result. Their real React-element `children` preserve secure
|
|
48
50
|
* containment and deliberately make child-independent layout caching invalid.
|
|
49
51
|
*/
|
|
50
|
-
export function resolvePagePrerender(root: SegmentNode): Map<string,
|
|
51
|
-
const result = new Map<string,
|
|
52
|
+
export function resolvePagePrerender(root: SegmentNode): Map<string, RoutePrerender> {
|
|
53
|
+
const result = new Map<string, RoutePrerender>();
|
|
52
54
|
|
|
53
|
-
function walk(node: SegmentNode, ancestorStack:
|
|
55
|
+
function walk(node: SegmentNode, ancestorStack: RoutePrerender[]) {
|
|
54
56
|
if (node.segmentType === 'intercepting' || node.segmentType === 'private') return;
|
|
55
57
|
|
|
56
58
|
// Check this segment's layout for a prerender export
|
|
57
|
-
const layoutValue = node.layout ?
|
|
59
|
+
const layoutValue = node.layout ? declaredPrerender(node.layout, 'layout') : undefined;
|
|
58
60
|
const stack = layoutValue !== undefined ? [layoutValue, ...ancestorStack] : ancestorStack;
|
|
59
61
|
|
|
60
62
|
if (node.page) {
|
|
61
|
-
const pageValue =
|
|
63
|
+
const pageValue = declaredPrerender(node.page, 'page');
|
|
62
64
|
// Page's own value takes priority; otherwise use nearest ancestor
|
|
63
65
|
const resolved = pageValue !== undefined ? pageValue : stack[0];
|
|
64
66
|
// Only record if the resolved value is truthy (prerender: true or options object)
|
|
@@ -76,10 +78,23 @@ export function resolvePagePrerender(root: SegmentNode): Map<string, PrerenderEx
|
|
|
76
78
|
return result;
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
/**
|
|
82
|
+
* The `prerender` a file declares. An options object with any problem reads
|
|
83
|
+
* as `false`, not as "undeclared": the build fails on it anyway, but in dev
|
|
84
|
+
* the error overlay is up while this plugin keeps re-resolving from disk, and
|
|
85
|
+
* "undeclared" would let the page inherit an ancestor's `prerender: true` —
|
|
86
|
+
* caching a page whose author wrote `prerender: false` next to a typo.
|
|
87
|
+
* Dynamic is the safe default: it can only be slower, never stale.
|
|
88
|
+
*/
|
|
89
|
+
function declaredPrerender(file: RouteFile, kind: 'layout' | 'page'): RoutePrerender | undefined {
|
|
90
|
+
const { options, problems } = readRouteOptions(file.filePath, kind);
|
|
91
|
+
return problems.length > 0 ? false : options?.prerender;
|
|
92
|
+
}
|
|
93
|
+
|
|
79
94
|
/**
|
|
80
95
|
* Build the `cache.component` options source text from a resolved value.
|
|
81
96
|
*/
|
|
82
|
-
function buildOptionsSource(value:
|
|
97
|
+
function buildOptionsSource(value: RoutePrerender): string {
|
|
83
98
|
if (value === true) return '{ prerender: true }';
|
|
84
99
|
if (typeof value === 'object') {
|
|
85
100
|
const parts = ['prerender: true'];
|
|
@@ -162,7 +177,7 @@ function findDefaultExport(program: { body: AstNode[] }, source: string): Defaul
|
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
export function timberPrerenderSugar(ctx: PluginContext): Plugin {
|
|
165
|
-
let resolvedPages: Map<string,
|
|
180
|
+
let resolvedPages: Map<string, RoutePrerender> | null = null;
|
|
166
181
|
/** The route tree `resolvedPages` was computed from — a rescan replaces it. */
|
|
167
182
|
let resolvedFor: PluginContext['routeTree'] | undefined;
|
|
168
183
|
|
|
@@ -182,18 +197,18 @@ export function timberPrerenderSugar(ctx: PluginContext): Plugin {
|
|
|
182
197
|
|
|
183
198
|
/**
|
|
184
199
|
* Dev: an edit can change the resolved prerender value of pages other
|
|
185
|
-
* than the edited file — a layout's `
|
|
200
|
+
* than the edited file — a layout's `layoutOptions.prerender` cascades to
|
|
186
201
|
* every descendant page. Vite re-transforms only the edited file, so
|
|
187
202
|
* the pages whose value changed are added to the update; through the
|
|
188
203
|
* RSC entry's HMR boundary they re-execute with the new wrapping
|
|
189
204
|
* (TIM-1588: dev caches prerendered output, so a stale wrapping is
|
|
190
|
-
* observable — a page switched to `prerender
|
|
205
|
+
* observable — a page switched to `prerender: false` would still be
|
|
191
206
|
* captured under the build rules). Runs after timber-routing's watcher
|
|
192
207
|
* rescan, which happens synchronously when the event fires.
|
|
193
208
|
*/
|
|
194
209
|
hotUpdate({ file, modules }) {
|
|
195
210
|
if (this.environment.name !== 'rsc' || !file.startsWith(ctx.appDir)) return;
|
|
196
|
-
const previous = resolvedPages ?? new Map<string,
|
|
211
|
+
const previous = resolvedPages ?? new Map<string, RoutePrerender>();
|
|
197
212
|
// Values are read from disk (mtime-checked), so resolve again even
|
|
198
213
|
// when the tree object is unchanged.
|
|
199
214
|
resolvedPages = null;
|
|
@@ -240,7 +255,8 @@ export function timberPrerenderSugar(ctx: PluginContext): Plugin {
|
|
|
240
255
|
if (value) {
|
|
241
256
|
const relPath = id.replace(ctx.root + '/', '');
|
|
242
257
|
console.warn(
|
|
243
|
-
`[timber] ${relPath}:
|
|
258
|
+
`[timber] ${relPath}: prerender applies to this page (from its pageOptions or an ` +
|
|
259
|
+
`ancestor layout's layoutOptions) but the default ` +
|
|
244
260
|
`export cannot be wrapped (re-export or missing). The prerender declaration ` +
|
|
245
261
|
`will be ignored for this file.`
|
|
246
262
|
);
|
package/src/plugins/routing.ts
CHANGED
|
@@ -114,7 +114,9 @@ export function timberRouting(ctx: PluginContext): Plugin {
|
|
|
114
114
|
// an unattributed React error on an unrelated page (TIM-1329). Never
|
|
115
115
|
// deduplicated against `warnedFiles`: an error must not be downgraded to
|
|
116
116
|
// silence by an earlier scan in the same process.
|
|
117
|
-
const conventionWarnings = lintConventions(tree, ctx.appDir
|
|
117
|
+
const conventionWarnings = lintConventions(tree, ctx.appDir, {
|
|
118
|
+
defaultLayoutLifetime: ctx.config.defaultLayoutLifetime,
|
|
119
|
+
});
|
|
118
120
|
const fatal = conventionWarnings.filter((w) => w.level === 'error');
|
|
119
121
|
if (fatal.length > 0) {
|
|
120
122
|
throw new Error(formatConventionWarnings(fatal, { color: false }));
|
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
* empty pages, confusing React errors).
|
|
10
10
|
*
|
|
11
11
|
* A check emits `level: 'error'` only when the misconfiguration is *proven*
|
|
12
|
-
* (never inferred from an absence the analysis cannot see through) and
|
|
13
|
-
* to rendering
|
|
12
|
+
* (never inferred from an absence the analysis cannot see through) and either
|
|
13
|
+
* fatal to rendering or a declaration that provably does nothing — a CSRF
|
|
14
|
+
* exemption the gate never reads, a route option the build cannot read, a
|
|
15
|
+
* middleware.ts in a slot. The developer believes the declaration is in
|
|
16
|
+
* effect, so silence would ship the wrong behavior. `plugins/routing.ts` turns those into a thrown build error,
|
|
14
17
|
* so a false positive there refuses a working app — see
|
|
15
18
|
* `classifyClientBoundaryFile` for how that bar is met.
|
|
16
19
|
*
|
|
@@ -28,7 +31,10 @@ import {
|
|
|
28
31
|
fileHasDirective,
|
|
29
32
|
fileHasStarExport,
|
|
30
33
|
getCsrfExport,
|
|
34
|
+
isScriptExtension,
|
|
31
35
|
} from './export-detect.ts';
|
|
36
|
+
import { checkRouteOptions } from './route-options-lint.ts';
|
|
37
|
+
import type { SegmentLifetime } from '../server/types.ts';
|
|
32
38
|
|
|
33
39
|
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
34
40
|
|
|
@@ -50,7 +56,12 @@ export interface ConventionWarning {
|
|
|
50
56
|
*
|
|
51
57
|
* Returns an array of warnings. Empty array means everything looks good.
|
|
52
58
|
*/
|
|
53
|
-
export function lintConventions(
|
|
59
|
+
export function lintConventions(
|
|
60
|
+
tree: RouteTree,
|
|
61
|
+
appDir: string,
|
|
62
|
+
/** The config the checks depend on, as the build resolved it. */
|
|
63
|
+
config: { defaultLayoutLifetime: SegmentLifetime | undefined }
|
|
64
|
+
): ConventionWarning[] {
|
|
54
65
|
const warnings: ConventionWarning[] = [];
|
|
55
66
|
|
|
56
67
|
// Check 1: app/ directory exists (caller should check before scanning,
|
|
@@ -90,6 +101,10 @@ export function lintConventions(tree: RouteTree, appDir: string): ConventionWarn
|
|
|
90
101
|
if (tree.proxy) checkCsrfExport(tree.proxy, 'proxy.ts', warnings);
|
|
91
102
|
if (tree.globalError) checkCsrfExport(tree.globalError, 'global-error', warnings);
|
|
92
103
|
|
|
104
|
+
// Check 10: layoutOptions / pageOptions the build cannot read, unknown
|
|
105
|
+
// keys, and the removed floating exports (design/53)
|
|
106
|
+
checkRouteOptions(tree.root, warnings, 'main', config.defaultLayoutLifetime ?? 'request');
|
|
107
|
+
|
|
93
108
|
return warnings;
|
|
94
109
|
}
|
|
95
110
|
|
|
@@ -361,10 +376,6 @@ function checkDefaultExports(node: SegmentNode, warnings: ConventionWarning[]):
|
|
|
361
376
|
}
|
|
362
377
|
}
|
|
363
378
|
|
|
364
|
-
function isScriptExtension(ext: string): boolean {
|
|
365
|
-
return ext === 'tsx' || ext === 'ts' || ext === 'jsx' || ext === 'js';
|
|
366
|
-
}
|
|
367
|
-
|
|
368
379
|
function checkFileDefaultExport(
|
|
369
380
|
filePath: string,
|
|
370
381
|
fileType: string,
|
|
@@ -33,9 +33,14 @@ interface ProgramNode {
|
|
|
33
33
|
body: AstNode[];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Parse a module. `lang` defaults to `tsx`; pass `ts` for `.ts` files, where
|
|
38
|
+
* an angle-bracket cast or a generic arrow (`<T>(x: T) => x`) is valid
|
|
39
|
+
* TypeScript but a TSX parse error.
|
|
40
|
+
*/
|
|
41
|
+
export function tryParse(source: string, lang: 'ts' | 'tsx' = 'tsx'): ProgramNode | null {
|
|
37
42
|
try {
|
|
38
|
-
return parseAst(source, { lang
|
|
43
|
+
return parseAst(source, { lang }) as unknown as ProgramNode;
|
|
39
44
|
} catch {
|
|
40
45
|
return null;
|
|
41
46
|
}
|
|
@@ -193,7 +198,7 @@ const FUNCTION_LIKE = new Set([
|
|
|
193
198
|
* Expression wrappers that erase at runtime and so cannot change where a value
|
|
194
199
|
* was constructed: `X as T`, `X satisfies T`, `<T>X`, `X!`, `X<T>`, `(X)`.
|
|
195
200
|
*/
|
|
196
|
-
const TRANSPARENT_WRAPPERS = new Set([
|
|
201
|
+
export const TRANSPARENT_WRAPPERS: ReadonlySet<string> = new Set([
|
|
197
202
|
'TSAsExpression',
|
|
198
203
|
'TSSatisfiesExpression',
|
|
199
204
|
'TSTypeAssertion',
|
|
@@ -312,119 +317,6 @@ export function fileHasStarExport(filePath: string): boolean {
|
|
|
312
317
|
}
|
|
313
318
|
}
|
|
314
319
|
|
|
315
|
-
/**
|
|
316
|
-
* Parsed value of `export const prerender` from a route file.
|
|
317
|
-
*
|
|
318
|
-
* - `true` / `false` — literal boolean
|
|
319
|
-
* - `{ ttl?, tags? }` — ISR options object (prerender: true is implied)
|
|
320
|
-
* - `undefined` — no `export const prerender` found
|
|
321
|
-
*
|
|
322
|
-
* See design/45-cache-lifetimes.md §"Route-Level Static".
|
|
323
|
-
*/
|
|
324
|
-
export type PrerenderExportValue = boolean | { ttl?: number; tags?: string[] };
|
|
325
|
-
|
|
326
|
-
function extractLiteralValue(node: AstNode): unknown {
|
|
327
|
-
if (!node) return undefined;
|
|
328
|
-
const n = node as any;
|
|
329
|
-
if (n.type === 'Literal') return n.value;
|
|
330
|
-
if (n.type === 'UnaryExpression' && n.operator === '-' && n.argument?.type === 'Literal') {
|
|
331
|
-
return -(n.argument.value as number);
|
|
332
|
-
}
|
|
333
|
-
if (n.type === 'ArrayExpression') {
|
|
334
|
-
const elements = n.elements as AstNode[] | undefined;
|
|
335
|
-
if (!elements) return undefined;
|
|
336
|
-
const result: unknown[] = [];
|
|
337
|
-
for (const el of elements) {
|
|
338
|
-
const v = extractLiteralValue(el);
|
|
339
|
-
if (v === undefined) return undefined;
|
|
340
|
-
result.push(v);
|
|
341
|
-
}
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
return undefined;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function extractObjectLiteral(node: AstNode): Record<string, unknown> | undefined {
|
|
348
|
-
if ((node as any).type !== 'ObjectExpression') return undefined;
|
|
349
|
-
const props = (node as any).properties as AstNode[] | undefined;
|
|
350
|
-
if (!props) return undefined;
|
|
351
|
-
const result: Record<string, unknown> = {};
|
|
352
|
-
for (const prop of props) {
|
|
353
|
-
const p = prop as any;
|
|
354
|
-
if (p.type === 'SpreadElement') return undefined;
|
|
355
|
-
if (p.type !== 'Property' || p.computed) return undefined;
|
|
356
|
-
const key =
|
|
357
|
-
p.key?.type === 'Identifier'
|
|
358
|
-
? p.key.name
|
|
359
|
-
: p.key?.type === 'Literal'
|
|
360
|
-
? String(p.key.value)
|
|
361
|
-
: undefined;
|
|
362
|
-
if (!key) return undefined;
|
|
363
|
-
const value = extractLiteralValue(p.value);
|
|
364
|
-
if (value === undefined) return undefined;
|
|
365
|
-
result[key] = value;
|
|
366
|
-
}
|
|
367
|
-
return result;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Extract the value of `export const prerender` from a file.
|
|
372
|
-
* Returns undefined if the file doesn't export `prerender` or can't be parsed.
|
|
373
|
-
*
|
|
374
|
-
* Supports:
|
|
375
|
-
* export const prerender = true;
|
|
376
|
-
* export const prerender = false;
|
|
377
|
-
* export const prerender = { ttl: 3600, tags: ['docs'] };
|
|
378
|
-
*/
|
|
379
|
-
export function getPrerenderExport(filePath: string): PrerenderExportValue | undefined {
|
|
380
|
-
if (!existsSync(filePath)) return undefined;
|
|
381
|
-
try {
|
|
382
|
-
const source = readFileCached(filePath);
|
|
383
|
-
const program = tryParse(source);
|
|
384
|
-
if (!program) return undefined;
|
|
385
|
-
|
|
386
|
-
for (const stmt of program.body) {
|
|
387
|
-
if (stmt.type !== 'ExportNamedDeclaration') continue;
|
|
388
|
-
if (stmt.exportKind === 'type') continue;
|
|
389
|
-
if (!stmt.declaration) continue;
|
|
390
|
-
const decl = stmt.declaration;
|
|
391
|
-
if (decl.type !== 'VariableDeclaration') continue;
|
|
392
|
-
const declarations = decl.declarations as
|
|
393
|
-
| Array<{
|
|
394
|
-
id?: { name?: string };
|
|
395
|
-
init?: AstNode;
|
|
396
|
-
}>
|
|
397
|
-
| undefined;
|
|
398
|
-
if (!declarations) continue;
|
|
399
|
-
for (const d of declarations) {
|
|
400
|
-
if (d.id?.name !== 'prerender' || !d.init) continue;
|
|
401
|
-
const init = d.init as any;
|
|
402
|
-
if (init.type === 'Literal' && typeof init.value === 'boolean') {
|
|
403
|
-
return init.value;
|
|
404
|
-
}
|
|
405
|
-
if (init.type === 'ObjectExpression') {
|
|
406
|
-
const obj = extractObjectLiteral(init);
|
|
407
|
-
if (!obj) return undefined;
|
|
408
|
-
const result: { ttl?: number; tags?: string[] } = {};
|
|
409
|
-
if ('ttl' in obj && typeof obj.ttl === 'number') result.ttl = obj.ttl;
|
|
410
|
-
if (
|
|
411
|
-
'tags' in obj &&
|
|
412
|
-
Array.isArray(obj.tags) &&
|
|
413
|
-
obj.tags.every((t: unknown) => typeof t === 'string')
|
|
414
|
-
) {
|
|
415
|
-
result.tags = obj.tags as string[];
|
|
416
|
-
}
|
|
417
|
-
return result;
|
|
418
|
-
}
|
|
419
|
-
return undefined;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return undefined;
|
|
423
|
-
} catch {
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
320
|
/**
|
|
429
321
|
* How a file declares the per-route CSRF exemption.
|
|
430
322
|
*
|
|
@@ -491,7 +383,7 @@ function specifierName(node: { name?: string; value?: unknown } | undefined): st
|
|
|
491
383
|
}
|
|
492
384
|
|
|
493
385
|
/** Whether a destructuring pattern binds `name` anywhere inside it. */
|
|
494
|
-
function patternBinds(node: unknown, name: string): boolean {
|
|
386
|
+
export function patternBinds(node: unknown, name: string): boolean {
|
|
495
387
|
if (!node || typeof node !== 'object') return false;
|
|
496
388
|
const n = node as Record<string, unknown>;
|
|
497
389
|
switch (n.type) {
|
|
@@ -534,3 +426,8 @@ export function fileHasDirective(filePath: string, directive: string): boolean {
|
|
|
534
426
|
return false;
|
|
535
427
|
}
|
|
536
428
|
}
|
|
429
|
+
|
|
430
|
+
/** Route files the AST checks can read; `.mdx` and `.json` are skipped. */
|
|
431
|
+
export function isScriptExtension(ext: string): boolean {
|
|
432
|
+
return ext === 'tsx' || ext === 'ts' || ext === 'jsx' || ext === 'js';
|
|
433
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention-lint check for route-module options (design/53 §"Route-module
|
|
3
|
+
* options"): `layoutOptions` / `pageOptions` the build cannot read, and
|
|
4
|
+
* options declared where nothing reads them. Called from
|
|
5
|
+
* `lintConventions` in `convention-lint.ts`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ConventionWarning } from './convention-lint.ts';
|
|
9
|
+
import { fileHasAnyExport, isScriptExtension } from './export-detect.ts';
|
|
10
|
+
import { readRouteOptions } from './route-options.ts';
|
|
11
|
+
import type { RouteFile, SegmentNode } from './types.ts';
|
|
12
|
+
import type { LayoutOptions, PageOptions, SegmentLifetime } from '../server/types.ts';
|
|
13
|
+
import { ROUTE_OPTIONS_EXPORT, type RouteOptionsKind } from '../shared/route-options-export.ts';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fail the build on a `layoutOptions` / `pageOptions` the build cannot read.
|
|
17
|
+
*
|
|
18
|
+
* Proven from source and fatal in the sense the error level requires: the
|
|
19
|
+
* developer declared an option that would otherwise silently do nothing — a
|
|
20
|
+
* misspelled key, a value the build cannot read, an options object in the
|
|
21
|
+
* wrong file kind, or a floating `export const prerender` that no longer
|
|
22
|
+
* prerenders. See `routing/route-options.ts` for what is accepted.
|
|
23
|
+
*/
|
|
24
|
+
export function checkRouteOptions(
|
|
25
|
+
node: SegmentNode,
|
|
26
|
+
warnings: ConventionWarning[],
|
|
27
|
+
position: RoutePosition,
|
|
28
|
+
/** The app's `defaultLayoutLifetime` (design/53 §"App-wide default"). */
|
|
29
|
+
defaultLayoutLifetime: SegmentLifetime,
|
|
30
|
+
/** The params named on the path above this segment. */
|
|
31
|
+
ancestorParams: readonly string[] = []
|
|
32
|
+
): void {
|
|
33
|
+
const here: RoutePosition = node.segmentType === 'intercepting' ? 'intercepting' : position;
|
|
34
|
+
const pathParams = node.paramName ? [...ancestorParams, node.paramName] : ancestorParams;
|
|
35
|
+
const files: Array<[RouteOptionsKind, RouteFile | undefined]> = [
|
|
36
|
+
['layout', node.layout],
|
|
37
|
+
['page', node.page],
|
|
38
|
+
];
|
|
39
|
+
for (const [kind, file] of files) {
|
|
40
|
+
if (!file || !isScriptExtension(file.extension)) continue;
|
|
41
|
+
const { options, problems } = readRouteOptions(file.filePath, kind);
|
|
42
|
+
problems.push(
|
|
43
|
+
...inertOptions(options, here),
|
|
44
|
+
...paramsOffPath(options, pathParams),
|
|
45
|
+
...keyWithoutDocument(options, kind === 'layout' ? defaultLayoutLifetime : 'request')
|
|
46
|
+
);
|
|
47
|
+
if (problems.length === 0) continue;
|
|
48
|
+
warnings.push({
|
|
49
|
+
id: `ROUTE_OPTIONS_INVALID:${file.filePath}`,
|
|
50
|
+
summary: `${kind}.${file.extension} has invalid ${ROUTE_OPTIONS_EXPORT[kind]}: ${file.filePath}`,
|
|
51
|
+
details:
|
|
52
|
+
` File: ${file.filePath}\n\n` +
|
|
53
|
+
problems.map((problem) => ` - ${problem}\n`).join('') +
|
|
54
|
+
'\n Options are read from source at build time, so they must be one object\n' +
|
|
55
|
+
' literal of literal values.\n',
|
|
56
|
+
level: 'error',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (node.default && isScriptExtension(node.default.extension)) {
|
|
60
|
+
const declared = fileHasAnyExport(node.default.filePath, OPTION_EXPORT_NAMES);
|
|
61
|
+
if (declared.size > 0) {
|
|
62
|
+
warnings.push({
|
|
63
|
+
id: `ROUTE_OPTIONS_INVALID:${node.default.filePath}`,
|
|
64
|
+
summary: `default.${node.default.extension} takes no route options: ${node.default.filePath}`,
|
|
65
|
+
details:
|
|
66
|
+
` File: ${node.default.filePath}\n\n` +
|
|
67
|
+
` default.tsx exports ${[...declared].join(', ')}, which nothing reads.\n` +
|
|
68
|
+
' To fix: remove the export; declare options on the slot page or layout.\n',
|
|
69
|
+
level: 'error',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const child of node.children) {
|
|
74
|
+
checkRouteOptions(child, warnings, here, defaultLayoutLifetime, pathParams);
|
|
75
|
+
}
|
|
76
|
+
for (const slot of Object.values(node.slots)) {
|
|
77
|
+
const slotPosition = here === 'intercepting' ? here : 'slot';
|
|
78
|
+
checkRouteOptions(slot, warnings, slotPosition, defaultLayoutLifetime, pathParams);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A `key` applies only to a `'document'` segment; on any other it would
|
|
84
|
+
* silently do nothing. A layout that declares no lifetime takes the app's
|
|
85
|
+
* `defaultLayoutLifetime`, so under a `'document'` default it may declare a
|
|
86
|
+
* key alone. A page always defaults to `'request'`.
|
|
87
|
+
*/
|
|
88
|
+
function keyWithoutDocument(
|
|
89
|
+
options: LayoutOptions | PageOptions | undefined,
|
|
90
|
+
defaultLifetime: SegmentLifetime
|
|
91
|
+
): string[] {
|
|
92
|
+
if (options?.key === undefined || (options.lifetime ?? defaultLifetime) === 'document') return [];
|
|
93
|
+
return [
|
|
94
|
+
"key applies only to lifetime: 'document'. Declare `lifetime: 'document'` or remove key.",
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A key's `segmentParams` must name params on the segment's path — the
|
|
100
|
+
* segment's own and every ancestor's, slots included. Anything else could
|
|
101
|
+
* never change, so the key would silently ignore what the author meant
|
|
102
|
+
* (design/53 §"Segment keys").
|
|
103
|
+
*/
|
|
104
|
+
function paramsOffPath(
|
|
105
|
+
options: LayoutOptions | PageOptions | undefined,
|
|
106
|
+
pathParams: readonly string[]
|
|
107
|
+
): string[] {
|
|
108
|
+
const declared = options?.key?.segmentParams ?? [];
|
|
109
|
+
return declared
|
|
110
|
+
.filter((name) => !pathParams.includes(name))
|
|
111
|
+
.map(
|
|
112
|
+
(name) =>
|
|
113
|
+
`key.segmentParams names "${name}", which is not a param on this segment's path. ` +
|
|
114
|
+
(pathParams.length > 0
|
|
115
|
+
? `Params on the path: ${pathParams.join(', ')}.`
|
|
116
|
+
: 'This path has no params.')
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Where a segment sits decides which options take effect there.
|
|
122
|
+
* - `main`: the matched route chain. Every option applies.
|
|
123
|
+
* - `slot`: a parallel slot. `prerender` applies to slot pages (the sugar
|
|
124
|
+
* walks slots); `deferSuspenseFor` does not — the hold is read from the
|
|
125
|
+
* main chain's modules only (`server/route-module-loader.ts`).
|
|
126
|
+
* - `intercepting`: an intercepting route and everything under it. It renders
|
|
127
|
+
* only on a soft navigation, through the slot resolver, and the sugar skips
|
|
128
|
+
* it, so no option applies.
|
|
129
|
+
*/
|
|
130
|
+
type RoutePosition = 'main' | 'slot' | 'intercepting';
|
|
131
|
+
|
|
132
|
+
const OPTION_EXPORT_NAMES = [
|
|
133
|
+
...Object.values(ROUTE_OPTIONS_EXPORT),
|
|
134
|
+
'prerender',
|
|
135
|
+
'deferSuspenseFor',
|
|
136
|
+
] as const;
|
|
137
|
+
|
|
138
|
+
function inertOptions(
|
|
139
|
+
options: LayoutOptions | PageOptions | undefined,
|
|
140
|
+
position: RoutePosition
|
|
141
|
+
): string[] {
|
|
142
|
+
if (!options || position === 'main') return [];
|
|
143
|
+
const inert = Object.keys(options).filter(
|
|
144
|
+
(key) => position === 'intercepting' || key === 'deferSuspenseFor'
|
|
145
|
+
);
|
|
146
|
+
return inert.map((key) =>
|
|
147
|
+
position === 'intercepting'
|
|
148
|
+
? `${key} has no effect on an intercepting route: it renders only on a soft navigation, ` +
|
|
149
|
+
'through the slot that intercepts it. Declare it on the route being intercepted.'
|
|
150
|
+
: `${key} has no effect in a parallel slot: the hold is read from the main route's ` +
|
|
151
|
+
'layouts and page. Declare it there.'
|
|
152
|
+
);
|
|
153
|
+
}
|