@timber-js/app 0.2.0-alpha.240 → 0.2.0-alpha.242

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (408) hide show
  1. package/dist/_chunks/{actions-DIgnvDrG.js → actions-BkwgRwCl.js} +146 -12
  2. package/dist/_chunks/actions-BkwgRwCl.js.map +1 -0
  3. package/dist/_chunks/{als-registry-PPYstxK0.js → als-registry-C-iwbtvI.js} +4 -3
  4. package/dist/_chunks/{als-registry-PPYstxK0.js.map → als-registry-C-iwbtvI.js.map} +1 -1
  5. package/dist/_chunks/{als-slots-kbQrHTzm.js → als-slots-CVTF-AMz.js} +3 -3
  6. package/dist/_chunks/als-slots-CVTF-AMz.js.map +1 -0
  7. package/dist/_chunks/{cache-api-uWQwuxWb.js → cache-api-BGA7c5qJ.js} +5 -5
  8. package/dist/_chunks/{cache-api-uWQwuxWb.js.map → cache-api-BGA7c5qJ.js.map} +1 -1
  9. package/dist/_chunks/{chains-C7CExrUI.js → chains-Cuwwjv6T.js} +2 -2
  10. package/dist/_chunks/{chains-C7CExrUI.js.map → chains-Cuwwjv6T.js.map} +1 -1
  11. package/dist/_chunks/chains-LGjBHfSN.js +1 -0
  12. package/dist/_chunks/{classify-Cj9EeZoL.js → classify-Y8S9C0Na.js} +2 -2
  13. package/dist/_chunks/{classify-Cj9EeZoL.js.map → classify-Y8S9C0Na.js.map} +1 -1
  14. package/dist/_chunks/{cli-check-C3QOAru7.js → cli-check-KeE1QaIx.js} +7 -6
  15. package/dist/_chunks/cli-check-KeE1QaIx.js.map +1 -0
  16. package/dist/_chunks/{cli-schema-sync-DQUS_o3V.js → cli-schema-sync-DZEF31wd.js} +2 -2
  17. package/dist/_chunks/{cli-schema-sync-DQUS_o3V.js.map → cli-schema-sync-DZEF31wd.js.map} +1 -1
  18. package/dist/_chunks/{cli-schema-sync-BRxZz66D.js → cli-schema-sync-_y5O6MIg.js} +1 -1
  19. package/dist/_chunks/{client-dep-entries-ZETBdLgv.js → client-dep-entries-DpiwvoDi.js} +2 -2
  20. package/dist/_chunks/{client-dep-entries-ZETBdLgv.js.map → client-dep-entries-DpiwvoDi.js.map} +1 -1
  21. package/dist/_chunks/{cloudflare-Dk5Hqo-O.js → cloudflare-9dbhVOxS.js} +2 -2
  22. package/dist/_chunks/{cloudflare-Dk5Hqo-O.js.map → cloudflare-9dbhVOxS.js.map} +1 -1
  23. package/dist/_chunks/{convention-lint-BoVISNS6.js → convention-lint-0AEsPK2T.js} +378 -10
  24. package/dist/_chunks/convention-lint-0AEsPK2T.js.map +1 -0
  25. package/dist/_chunks/dev-server-CboXr8zX.js +1 -0
  26. package/dist/_chunks/{dev-server-C5R6jx8Q.js → dev-server-DYDr8KIc.js} +9 -3
  27. package/dist/_chunks/dev-server-DYDr8KIc.js.map +1 -0
  28. package/dist/_chunks/{dist-C1Rjlo6s.js → dist-GyaJm4GA.js} +18 -2
  29. package/dist/_chunks/dist-GyaJm4GA.js.map +1 -0
  30. package/dist/_chunks/{error-boundary-DB51f9ih.js → error-boundary-wuNvAJ4n.js} +11 -14
  31. package/dist/_chunks/error-boundary-wuNvAJ4n.js.map +1 -0
  32. package/dist/_chunks/{flight-source-node-D9cHBhjP.js → flight-source-node-KQsX_OhS.js} +4 -7
  33. package/dist/_chunks/flight-source-node-KQsX_OhS.js.map +1 -0
  34. package/dist/_chunks/{json-lossy-check-Y1GxqVX_.js → json-lossy-check-BVDALqMf.js} +2 -2
  35. package/dist/_chunks/{json-lossy-check-Y1GxqVX_.js.map → json-lossy-check-BVDALqMf.js.map} +1 -1
  36. package/dist/_chunks/key-headers-uIig1_mU.js +40 -0
  37. package/dist/_chunks/key-headers-uIig1_mU.js.map +1 -0
  38. package/dist/_chunks/{live-graph-BDQWvnMm.js → live-graph-VhzO7Ol9.js} +4 -4
  39. package/dist/_chunks/{live-graph-BDQWvnMm.js.map → live-graph-VhzO7Ol9.js.map} +1 -1
  40. package/dist/_chunks/{logger-DmRR9tmZ.js → logger-C4m8rfMy.js} +2 -2
  41. package/dist/_chunks/{logger-DmRR9tmZ.js.map → logger-C4m8rfMy.js.map} +1 -1
  42. package/dist/_chunks/metadata-routes-MXNjWOt5.js.map +1 -1
  43. package/dist/_chunks/{node-response-yp8zdyRp.js → node-response-8Vz29cGS.js} +2 -2
  44. package/dist/_chunks/{node-response-yp8zdyRp.js.map → node-response-8Vz29cGS.js.map} +1 -1
  45. package/dist/_chunks/{poison-scan-WQgUydF_.js → poison-scan-Dpl3ibG-.js} +2 -2
  46. package/dist/_chunks/{poison-scan-WQgUydF_.js.map → poison-scan-Dpl3ibG-.js.map} +1 -1
  47. package/dist/_chunks/{rsc-cache-key-D0cb0Gmc.js → rsc-cache-key-BGvUtMtN.js} +40 -4
  48. package/dist/_chunks/{rsc-cache-key-D0cb0Gmc.js.map → rsc-cache-key-BGvUtMtN.js.map} +1 -1
  49. package/dist/_chunks/{scanner-C9Lrf77z.js → scanner-CCEHN9Jg.js} +14 -81
  50. package/dist/_chunks/scanner-CCEHN9Jg.js.map +1 -0
  51. package/dist/_chunks/{sizeof-BISkSaU0.js → sizeof-CIF7fwSJ.js} +2 -2
  52. package/dist/_chunks/{sizeof-BISkSaU0.js.map → sizeof-CIF7fwSJ.js.map} +1 -1
  53. package/dist/_chunks/{walkers-Bxv4v7tX.js → walkers-BbotBhNG.js} +3 -3
  54. package/dist/_chunks/{walkers-Bxv4v7tX.js.map → walkers-BbotBhNG.js.map} +1 -1
  55. package/dist/adapters/cloudflare-dev.js +1 -1
  56. package/dist/adapters/cloudflare-kv-cache.js +2 -2
  57. package/dist/adapters/cloudflare.js +1 -1
  58. package/dist/analyze/crawl-entry.js +3 -3
  59. package/dist/analyze/graph-command.js +2 -2
  60. package/dist/cache/index.js +2 -2
  61. package/dist/cache/stores/memory.js +1 -1
  62. package/dist/cdn/workers-cache-purge.js +1 -1
  63. package/dist/cli-check.d.ts +3 -0
  64. package/dist/cli-check.d.ts.map +1 -1
  65. package/dist/cli.js +3 -3
  66. package/dist/client/browser-entry/router-init.d.ts +0 -1
  67. package/dist/client/browser-entry/router-init.d.ts.map +1 -1
  68. package/dist/client/error-boundary.js +1 -1
  69. package/dist/client/index.js +2 -2
  70. package/dist/client/index.js.map +1 -1
  71. package/dist/client/internal.js +4 -5
  72. package/dist/client/internal.js.map +1 -1
  73. package/dist/client/navigation-commit.d.ts +3 -5
  74. package/dist/client/navigation-commit.d.ts.map +1 -1
  75. package/dist/client/outlet-content-cache.d.ts +25 -30
  76. package/dist/client/outlet-content-cache.d.ts.map +1 -1
  77. package/dist/client/outlet-scope-context.d.ts +4 -4
  78. package/dist/client/outlet-scope-context.d.ts.map +1 -1
  79. package/dist/client/params-context.d.ts +1 -1
  80. package/dist/client/router-types.d.ts +3 -13
  81. package/dist/client/router-types.d.ts.map +1 -1
  82. package/dist/client/router.d.ts.map +1 -1
  83. package/dist/client/segment-cache.d.ts +2 -2
  84. package/dist/client/segment-outlet.d.ts +12 -13
  85. package/dist/client/segment-outlet.d.ts.map +1 -1
  86. package/dist/client/stale-segment.d.ts +2 -2
  87. package/dist/config-types.d.ts +22 -15
  88. package/dist/config-types.d.ts.map +1 -1
  89. package/dist/config-validation.d.ts.map +1 -1
  90. package/dist/cookies/define-cookie.d.ts.map +1 -1
  91. package/dist/cookies/index.js +5 -2
  92. package/dist/cookies/index.js.map +1 -1
  93. package/dist/index.d.ts +1 -0
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +109 -26
  96. package/dist/index.js.map +1 -1
  97. package/dist/native/rsc/cookies/define-cookie.js +6 -2
  98. package/dist/native/rsc/cookies/define-cookie.js.map +1 -1
  99. package/dist/native/rsc/manifest.json +12 -4
  100. package/dist/native/rsc/routing/segment-keys.js +11 -1
  101. package/dist/native/rsc/routing/segment-keys.js.map +1 -1
  102. package/dist/native/rsc/search-params/define.js +4 -1
  103. package/dist/native/rsc/search-params/define.js.map +1 -1
  104. package/dist/native/rsc/server/als-registry.js +2 -2
  105. package/dist/native/rsc/server/als-registry.js.map +1 -1
  106. package/dist/native/rsc/server/client-state-tree.js +13 -12
  107. package/dist/native/rsc/server/client-state-tree.js.map +1 -1
  108. package/dist/native/rsc/server/cookie-context.js +12 -0
  109. package/dist/native/rsc/server/cookie-context.js.map +1 -1
  110. package/dist/native/rsc/server/flight-source-node.js +2 -5
  111. package/dist/native/rsc/server/flight-source-node.js.map +1 -1
  112. package/dist/native/rsc/server/flight-source.js +8 -40
  113. package/dist/native/rsc/server/flight-source.js.map +1 -1
  114. package/dist/native/rsc/server/framework-stack-frames.js +18 -0
  115. package/dist/native/rsc/server/framework-stack-frames.js.map +1 -0
  116. package/dist/native/rsc/server/prebuilt-builder.js +15 -1
  117. package/dist/native/rsc/server/prebuilt-builder.js.map +1 -1
  118. package/dist/native/rsc/server/request-context.js +11 -5
  119. package/dist/native/rsc/server/request-context.js.map +1 -1
  120. package/dist/native/rsc/server/route-element-builder.js +29 -11
  121. package/dist/native/rsc/server/route-element-builder.js.map +1 -1
  122. package/dist/native/rsc/server/route-module-loader.js +14 -6
  123. package/dist/native/rsc/server/route-module-loader.js.map +1 -1
  124. package/dist/native/rsc/server/rsc-cache-key-guard.js +5 -1
  125. package/dist/native/rsc/server/rsc-cache-key-guard.js.map +1 -1
  126. package/dist/native/rsc/server/rsc-entry/render-route.js +10 -29
  127. package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
  128. package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +7 -2
  129. package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js.map +1 -1
  130. package/dist/native/rsc/server/rsc-entry/rsc-stream.js +2 -5
  131. package/dist/native/rsc/server/rsc-entry/rsc-stream.js.map +1 -1
  132. package/dist/native/rsc/server/segment-lifetime/document-outlet.js +24 -0
  133. package/dist/native/rsc/server/segment-lifetime/document-outlet.js.map +1 -0
  134. package/dist/native/rsc/server/segment-lifetime/key-digest.js +74 -0
  135. package/dist/native/rsc/server/segment-lifetime/key-digest.js.map +1 -0
  136. package/dist/native/rsc/server/segment-lifetime/outlet-gate.js +44 -0
  137. package/dist/native/rsc/server/segment-lifetime/outlet-gate.js.map +1 -0
  138. package/dist/native/rsc/server/segment-lifetime/read-rule.js +78 -0
  139. package/dist/native/rsc/server/segment-lifetime/read-rule.js.map +1 -0
  140. package/dist/native/rsc/server/segment-lifetime/read-scope.js +41 -0
  141. package/dist/native/rsc/server/segment-lifetime/read-scope.js.map +1 -0
  142. package/dist/native/rsc/server/segment-lifetime/segment-key.js +64 -0
  143. package/dist/native/rsc/server/segment-lifetime/segment-key.js.map +1 -0
  144. package/dist/native/rsc/server/segment-lifetime/slot-outlets.js +72 -0
  145. package/dist/native/rsc/server/segment-lifetime/slot-outlets.js.map +1 -0
  146. package/dist/native/rsc/server/slot-resolver.js +51 -27
  147. package/dist/native/rsc/server/slot-resolver.js.map +1 -1
  148. package/dist/native/rsc/server/slot-subtree-contain.js +17 -89
  149. package/dist/native/rsc/server/slot-subtree-contain.js.map +1 -1
  150. package/dist/native/rsc/server/subtree-walk.js +140 -0
  151. package/dist/native/rsc/server/subtree-walk.js.map +1 -0
  152. package/dist/native/rsc/server/vite-handoff-rsc.js.map +1 -1
  153. package/dist/native/rsc/shared/als-slots.js +2 -2
  154. package/dist/native/rsc/shared/als-slots.js.map +1 -1
  155. package/dist/native/rsc/shared/cookie-read-through.js +5 -0
  156. package/dist/native/rsc/shared/cookie-read-through.js.map +1 -0
  157. package/dist/native/rsc/shared/key-headers.js +20 -0
  158. package/dist/native/rsc/shared/key-headers.js.map +1 -0
  159. package/dist/native/rsc/shared/outlet-decision.js.map +1 -1
  160. package/dist/native/rsc/shared/route-options-export.js +8 -0
  161. package/dist/native/rsc/shared/route-options-export.js.map +1 -0
  162. package/dist/native/rsc/shared/rsc-cache-key.js +19 -3
  163. package/dist/native/rsc/shared/rsc-cache-key.js.map +1 -1
  164. package/dist/native/rsc/shims/headers.js +3 -4
  165. package/dist/native/rsc/shims/headers.js.map +1 -1
  166. package/dist/native/ssr/client/outlet-content-cache.js +12 -18
  167. package/dist/native/ssr/client/outlet-content-cache.js.map +1 -1
  168. package/dist/native/ssr/client/outlet-scope-context.js.map +1 -1
  169. package/dist/native/ssr/client/segment-outlet.js +6 -19
  170. package/dist/native/ssr/client/segment-outlet.js.map +1 -1
  171. package/dist/native/ssr/cookies/define-cookie.js +6 -2
  172. package/dist/native/ssr/cookies/define-cookie.js.map +1 -1
  173. package/dist/native/ssr/manifest.json +5 -1
  174. package/dist/native/ssr/search-params/define.js +4 -1
  175. package/dist/native/ssr/search-params/define.js.map +1 -1
  176. package/dist/native/ssr/server/als-registry.js +2 -2
  177. package/dist/native/ssr/server/als-registry.js.map +1 -1
  178. package/dist/native/ssr/server/client-state-tree.js +13 -12
  179. package/dist/native/ssr/server/client-state-tree.js.map +1 -1
  180. package/dist/native/ssr/server/cookie-context.js +12 -0
  181. package/dist/native/ssr/server/cookie-context.js.map +1 -1
  182. package/dist/native/ssr/server/flight-source-node.js +2 -5
  183. package/dist/native/ssr/server/flight-source-node.js.map +1 -1
  184. package/dist/native/ssr/server/flight-source.js +1 -1
  185. package/dist/native/ssr/server/flight-source.js.map +1 -1
  186. package/dist/native/ssr/server/framework-stack-frames.js +18 -0
  187. package/dist/native/ssr/server/framework-stack-frames.js.map +1 -0
  188. package/dist/native/ssr/server/request-context.js +11 -5
  189. package/dist/native/ssr/server/request-context.js.map +1 -1
  190. package/dist/native/ssr/server/rsc-cache-key-guard.js +5 -1
  191. package/dist/native/ssr/server/rsc-cache-key-guard.js.map +1 -1
  192. package/dist/native/ssr/server/segment-lifetime/key-digest.js +6 -0
  193. package/dist/native/ssr/server/segment-lifetime/key-digest.js.map +1 -0
  194. package/dist/native/ssr/server/segment-lifetime/read-rule.js +78 -0
  195. package/dist/native/ssr/server/segment-lifetime/read-rule.js.map +1 -0
  196. package/dist/native/ssr/server/vite-handoff-rsc.js.map +1 -1
  197. package/dist/native/ssr/shared/als-slots.js +2 -2
  198. package/dist/native/ssr/shared/als-slots.js.map +1 -1
  199. package/dist/native/ssr/shared/cookie-read-through.js +5 -0
  200. package/dist/native/ssr/shared/cookie-read-through.js.map +1 -0
  201. package/dist/native/ssr/shared/key-headers.js +13 -0
  202. package/dist/native/ssr/shared/key-headers.js.map +1 -0
  203. package/dist/native/ssr/shared/rsc-cache-key.js +19 -3
  204. package/dist/native/ssr/shared/rsc-cache-key.js.map +1 -1
  205. package/dist/native/ssr/shims/headers.js +3 -4
  206. package/dist/native/ssr/shims/headers.js.map +1 -1
  207. package/dist/plugins/callsite-jsx.d.ts +8 -1
  208. package/dist/plugins/callsite-jsx.d.ts.map +1 -1
  209. package/dist/plugins/entries.d.ts.map +1 -1
  210. package/dist/plugins/prerender-sugar.d.ts +9 -8
  211. package/dist/plugins/prerender-sugar.d.ts.map +1 -1
  212. package/dist/plugins/routing.d.ts.map +1 -1
  213. package/dist/routing/convention-lint.d.ts +11 -3
  214. package/dist/routing/convention-lint.d.ts.map +1 -1
  215. package/dist/routing/export-detect.d.ts +50 -23
  216. package/dist/routing/export-detect.d.ts.map +1 -1
  217. package/dist/routing/index.js +2 -2
  218. package/dist/routing/route-options-lint.d.ts +36 -0
  219. package/dist/routing/route-options-lint.d.ts.map +1 -0
  220. package/dist/routing/route-options.d.ts +55 -0
  221. package/dist/routing/route-options.d.ts.map +1 -0
  222. package/dist/routing/segment-keys.d.ts +38 -4
  223. package/dist/routing/segment-keys.d.ts.map +1 -1
  224. package/dist/search-params/index.js +5 -2
  225. package/dist/search-params/index.js.map +1 -1
  226. package/dist/server/als-registry.d.ts +22 -13
  227. package/dist/server/als-registry.d.ts.map +1 -1
  228. package/dist/server/client-state-tree.d.ts +11 -10
  229. package/dist/server/client-state-tree.d.ts.map +1 -1
  230. package/dist/server/cookie-context.d.ts +3 -0
  231. package/dist/server/cookie-context.d.ts.map +1 -1
  232. package/dist/server/flight-source-node.d.ts +1 -6
  233. package/dist/server/flight-source-node.d.ts.map +1 -1
  234. package/dist/server/flight-source.d.ts +4 -28
  235. package/dist/server/flight-source.d.ts.map +1 -1
  236. package/dist/server/framework-stack-frames.d.ts +20 -0
  237. package/dist/server/framework-stack-frames.d.ts.map +1 -0
  238. package/dist/server/index.d.ts +1 -0
  239. package/dist/server/index.d.ts.map +1 -1
  240. package/dist/server/index.js +2 -2
  241. package/dist/server/internal.js +102 -28
  242. package/dist/server/internal.js.map +1 -1
  243. package/dist/server/prebuilt/capture-routes.d.ts +1 -1
  244. package/dist/server/prebuilt-builder.d.ts.map +1 -1
  245. package/dist/server/request-context.d.ts +6 -1
  246. package/dist/server/request-context.d.ts.map +1 -1
  247. package/dist/server/route-element-builder.d.ts +2 -2
  248. package/dist/server/route-element-builder.d.ts.map +1 -1
  249. package/dist/server/route-module-loader.d.ts +10 -2
  250. package/dist/server/route-module-loader.d.ts.map +1 -1
  251. package/dist/server/rsc-cache-key-guard.d.ts +3 -1
  252. package/dist/server/rsc-cache-key-guard.d.ts.map +1 -1
  253. package/dist/server/rsc-entry/helpers.d.ts +1 -1
  254. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  255. package/dist/server/rsc-entry/render-route.d.ts +10 -1
  256. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  257. package/dist/server/rsc-entry/revalidate-renderer.d.ts +12 -0
  258. package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
  259. package/dist/server/rsc-entry/rsc-stream.d.ts +2 -11
  260. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  261. package/dist/server/segment-lifetime/document-outlet.d.ts +66 -0
  262. package/dist/server/segment-lifetime/document-outlet.d.ts.map +1 -0
  263. package/dist/server/segment-lifetime/key-digest.d.ts +46 -0
  264. package/dist/server/segment-lifetime/key-digest.d.ts.map +1 -0
  265. package/dist/server/segment-lifetime/outlet-gate.d.ts +58 -0
  266. package/dist/server/segment-lifetime/outlet-gate.d.ts.map +1 -0
  267. package/dist/server/segment-lifetime/read-rule.d.ts +53 -0
  268. package/dist/server/segment-lifetime/read-rule.d.ts.map +1 -0
  269. package/dist/server/segment-lifetime/read-scope.d.ts +40 -0
  270. package/dist/server/segment-lifetime/read-scope.d.ts.map +1 -0
  271. package/dist/server/segment-lifetime/segment-key.d.ts +63 -0
  272. package/dist/server/segment-lifetime/segment-key.d.ts.map +1 -0
  273. package/dist/server/segment-lifetime/slot-outlets.d.ts +81 -0
  274. package/dist/server/segment-lifetime/slot-outlets.d.ts.map +1 -0
  275. package/dist/server/slot-resolver.d.ts +10 -5
  276. package/dist/server/slot-resolver.d.ts.map +1 -1
  277. package/dist/server/slot-subtree-contain.d.ts +2 -6
  278. package/dist/server/slot-subtree-contain.d.ts.map +1 -1
  279. package/dist/server/subtree-walk.d.ts +56 -0
  280. package/dist/server/subtree-walk.d.ts.map +1 -0
  281. package/dist/server/types.d.ts +75 -0
  282. package/dist/server/types.d.ts.map +1 -1
  283. package/dist/server/vite-handoff-rsc.d.ts +1 -10
  284. package/dist/server/vite-handoff-rsc.d.ts.map +1 -1
  285. package/dist/shared/als-slots.d.ts +12 -2
  286. package/dist/shared/als-slots.d.ts.map +1 -1
  287. package/dist/shared/cookie-read-through.d.ts +18 -0
  288. package/dist/shared/cookie-read-through.d.ts.map +1 -0
  289. package/dist/shared/key-headers.d.ts +13 -0
  290. package/dist/shared/key-headers.d.ts.map +1 -0
  291. package/dist/shared/outlet-decision.d.ts +16 -28
  292. package/dist/shared/outlet-decision.d.ts.map +1 -1
  293. package/dist/shared/payload-root.d.ts +1 -1
  294. package/dist/shared/route-options-export.d.ts +13 -0
  295. package/dist/shared/route-options-export.d.ts.map +1 -0
  296. package/dist/shared/rsc-cache-key.d.ts +22 -0
  297. package/dist/shared/rsc-cache-key.d.ts.map +1 -1
  298. package/dist/shared/segment-info.d.ts +7 -5
  299. package/dist/shared/segment-info.d.ts.map +1 -1
  300. package/dist/shims/headers.d.ts.map +1 -1
  301. package/docs/api/30-api-server.mdx +29 -0
  302. package/docs/api/32-api-cache.mdx +10 -4
  303. package/docs/api/34-api-config.mdx +5 -0
  304. package/docs/learn/09-streaming.mdx +6 -2
  305. package/docs/learn/10-caching.mdx +10 -4
  306. package/package.json +1 -1
  307. package/src/cli-check.ts +11 -3
  308. package/src/client/browser-entry/index.ts +0 -2
  309. package/src/client/browser-entry/router-init.ts +2 -4
  310. package/src/client/error-boundary.tsx +1 -1
  311. package/src/client/navigation-commit.ts +9 -14
  312. package/src/client/outlet-content-cache.ts +36 -42
  313. package/src/client/outlet-scope-context.ts +5 -5
  314. package/src/client/params-context.ts +1 -1
  315. package/src/client/router-types.ts +3 -14
  316. package/src/client/router.ts +1 -2
  317. package/src/client/rsc-fetch.ts +1 -1
  318. package/src/client/segment-cache.ts +2 -2
  319. package/src/client/segment-outlet.tsx +19 -45
  320. package/src/client/stale-segment.ts +2 -2
  321. package/src/config-types.ts +23 -15
  322. package/src/config-validation.ts +17 -1
  323. package/src/cookies/define-cookie.ts +5 -1
  324. package/src/index.ts +2 -1
  325. package/src/plugins/callsite-jsx.ts +104 -6
  326. package/src/plugins/entries.ts +3 -1
  327. package/src/plugins/prerender-sugar.ts +34 -18
  328. package/src/plugins/routing.ts +3 -1
  329. package/src/routing/convention-lint.ts +18 -7
  330. package/src/routing/export-detect.ts +14 -117
  331. package/src/routing/route-options-lint.ts +153 -0
  332. package/src/routing/route-options.ts +439 -0
  333. package/src/routing/scanner.ts +1 -1
  334. package/src/routing/segment-keys.ts +53 -4
  335. package/src/rsc-runtime/vendor-types.d.ts +5 -1
  336. package/src/search-params/define.ts +1 -1
  337. package/src/server/als-registry.ts +25 -17
  338. package/src/server/client-state-tree.ts +30 -27
  339. package/src/server/cookie-context.ts +17 -0
  340. package/src/server/flight-source-node.ts +1 -5
  341. package/src/server/flight-source.ts +8 -82
  342. package/src/server/framework-stack-frames.ts +41 -0
  343. package/src/server/index.ts +7 -0
  344. package/src/server/prebuilt/capture-routes.ts +1 -1
  345. package/src/server/prebuilt-builder.ts +30 -2
  346. package/src/server/request-context.ts +31 -6
  347. package/src/server/route-element-builder.ts +92 -18
  348. package/src/server/route-module-loader.ts +43 -10
  349. package/src/server/rsc-cache-key-guard.ts +17 -2
  350. package/src/server/rsc-entry/helpers.ts +1 -1
  351. package/src/server/rsc-entry/index.ts +16 -3
  352. package/src/server/rsc-entry/render-route.ts +22 -51
  353. package/src/server/rsc-entry/revalidate-renderer.ts +16 -2
  354. package/src/server/rsc-entry/rsc-stream.ts +3 -23
  355. package/src/server/segment-lifetime/document-outlet.ts +98 -0
  356. package/src/server/segment-lifetime/key-digest.ts +139 -0
  357. package/src/server/segment-lifetime/outlet-gate.ts +102 -0
  358. package/src/server/segment-lifetime/read-rule.ts +193 -0
  359. package/src/server/segment-lifetime/read-scope.ts +101 -0
  360. package/src/server/segment-lifetime/segment-key.ts +168 -0
  361. package/src/server/segment-lifetime/slot-outlets.ts +180 -0
  362. package/src/server/slot-resolver.ts +103 -60
  363. package/src/server/slot-subtree-contain.ts +35 -182
  364. package/src/server/subtree-walk.ts +316 -0
  365. package/src/server/types.ts +91 -0
  366. package/src/server/vite-handoff-rsc.ts +1 -12
  367. package/src/shared/als-slots.ts +19 -8
  368. package/src/shared/cookie-read-through.ts +18 -0
  369. package/src/shared/key-headers.ts +42 -0
  370. package/src/shared/outlet-decision.ts +16 -30
  371. package/src/shared/payload-root.ts +1 -1
  372. package/src/shared/route-options-export.ts +14 -0
  373. package/src/shared/rsc-cache-key.ts +41 -2
  374. package/src/shared/segment-info.ts +7 -5
  375. package/src/shims/headers.ts +5 -4
  376. package/dist/_chunks/actions-DIgnvDrG.js.map +0 -1
  377. package/dist/_chunks/als-slots-kbQrHTzm.js.map +0 -1
  378. package/dist/_chunks/chains-CSslTUdI.js +0 -1
  379. package/dist/_chunks/cli-check-C3QOAru7.js.map +0 -1
  380. package/dist/_chunks/convention-lint-BoVISNS6.js.map +0 -1
  381. package/dist/_chunks/dev-server-B8roKA3Q.js +0 -1
  382. package/dist/_chunks/dev-server-C5R6jx8Q.js.map +0 -1
  383. package/dist/_chunks/dist-C1Rjlo6s.js.map +0 -1
  384. package/dist/_chunks/error-boundary-DB51f9ih.js.map +0 -1
  385. package/dist/_chunks/flight-source-node-D9cHBhjP.js.map +0 -1
  386. package/dist/_chunks/scanner-C9Lrf77z.js.map +0 -1
  387. package/dist/native/rsc/server/segment-hash/capture.js +0 -107
  388. package/dist/native/rsc/server/segment-hash/capture.js.map +0 -1
  389. package/dist/native/rsc/server/segment-hash/outlet.js +0 -81
  390. package/dist/native/rsc/server/segment-hash/outlet.js.map +0 -1
  391. package/dist/native/rsc/server/segment-hash/stream-tap.js +0 -139
  392. package/dist/native/rsc/server/segment-hash/stream-tap.js.map +0 -1
  393. package/dist/native/rsc/server/segment-hash/value-hash.js +0 -171
  394. package/dist/native/rsc/server/segment-hash/value-hash.js.map +0 -1
  395. package/dist/native/ssr/server/segment-hash/value-hash.js +0 -162
  396. package/dist/native/ssr/server/segment-hash/value-hash.js.map +0 -1
  397. package/dist/server/segment-hash/capture.d.ts +0 -77
  398. package/dist/server/segment-hash/capture.d.ts.map +0 -1
  399. package/dist/server/segment-hash/outlet.d.ts +0 -65
  400. package/dist/server/segment-hash/outlet.d.ts.map +0 -1
  401. package/dist/server/segment-hash/stream-tap.d.ts +0 -49
  402. package/dist/server/segment-hash/stream-tap.d.ts.map +0 -1
  403. package/dist/server/segment-hash/value-hash.d.ts +0 -70
  404. package/dist/server/segment-hash/value-hash.d.ts.map +0 -1
  405. package/src/server/segment-hash/capture.ts +0 -232
  406. package/src/server/segment-hash/outlet.ts +0 -185
  407. package/src/server/segment-hash/stream-tap.ts +0 -244
  408. package/src/server/segment-hash/value-hash.ts +0 -338
@@ -0,0 +1,168 @@
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
+ * - **headers** — each named header's value as `Headers.get` returns it
16
+ * (trimmed, repeats joined with ", "), or null when absent, by lowercased
17
+ * name; headers have no codec, so equivalent spellings differ;
18
+ * - **cookies** — `codec.serialize(codec.parse(raw))` per definition. The raw
19
+ * value comes from the request's cookie jar, which reflects cookies the
20
+ * current server action set (design/53 open question 4), so an action's
21
+ * revalidated render issues digests from the values the browser will send
22
+ * next.
23
+ */
24
+
25
+ import type { CoercedParams } from '../../shared/param-value.ts';
26
+ import { ROUTE_OPTIONS_EXPORT, type RouteOptionsKind } from '../../shared/route-options-export.ts';
27
+ import { getCookieJar } from '../cookie-context.ts';
28
+ import { getHeaders, getSearchParams } from '../request-context.ts';
29
+ import { headerKeyProblem } from '../../shared/key-headers.ts';
30
+ import type { SegmentKey, SegmentLifetime } from '../types.ts';
31
+
32
+ /** A segment declared `lifetime: 'document'`, with the key it declared (if any). */
33
+ export interface DocumentLifetime {
34
+ key: SegmentKey;
35
+ }
36
+
37
+ /**
38
+ * The lifetime of a layout that declares none, at the end of `chain` (the
39
+ * segments from the root down to it, slot chains included): the app's
40
+ * `defaultLayoutLifetime`, except at or below an intercepting segment.
41
+ * Options there are a build error (`routing/route-options-lint.ts`), so a
42
+ * defaulted layout under an intercepting directory could never opt back to
43
+ * `'request'` — it keeps `'request'` instead (design/53 §"App-wide default").
44
+ * A page always defaults to `'request'`.
45
+ */
46
+ export function defaultLayoutLifetimeAt(
47
+ chain: readonly { segmentType?: string }[],
48
+ appDefault: SegmentLifetime
49
+ ): SegmentLifetime {
50
+ return chain.some((segment) => segment.segmentType === 'intercepting') ? 'request' : appDefault;
51
+ }
52
+
53
+ /**
54
+ * The module's lifetime: a `DocumentLifetime` when its options object
55
+ * declares `lifetime: 'document'`, or declares no lifetime and
56
+ * `defaultLifetime` is `'document'`; undefined otherwise. The build validated
57
+ * the object from source (`routing/route-options.ts`); this runtime read is
58
+ * what takes effect.
59
+ *
60
+ * @param defaultLifetime The lifetime of a module that declares none: the
61
+ * app's `defaultLayoutLifetime` for a layout, `'request'` for a page
62
+ * (design/53 §"App-wide default").
63
+ */
64
+ export function readDocumentLifetime(
65
+ mod: Record<string, unknown>,
66
+ kind: RouteOptionsKind,
67
+ defaultLifetime: SegmentLifetime
68
+ ): DocumentLifetime | undefined {
69
+ const exported = mod[ROUTE_OPTIONS_EXPORT[kind]];
70
+ const options = typeof exported === 'object' && exported !== null ? exported : {};
71
+ const lifetime = 'lifetime' in options ? options.lifetime : undefined;
72
+ if ((lifetime ?? defaultLifetime) !== 'document') return undefined;
73
+ const key = 'key' in options ? options.key : undefined;
74
+ // The module's own export, typed `satisfies LayoutOptions` / `PageOptions`
75
+ // in source and shape-checked by the build; at runtime it is an `object`.
76
+ const segmentKey = typeof key === 'object' && key !== null ? (key as SegmentKey) : {};
77
+ assertKeyableHeaders(segmentKey.headers);
78
+ return { key: segmentKey };
79
+ }
80
+
81
+ /**
82
+ * Refuse a header the key may not name, at runtime too: the build does not
83
+ * read every file kind (an MDX page's options go unlinted), and a credential
84
+ * must not become keyable — and readable — by skipping the lint.
85
+ */
86
+ function assertKeyableHeaders(headers: unknown): void {
87
+ if (headers === undefined) return;
88
+ if (!Array.isArray(headers) || !headers.every((h) => typeof h === 'string')) {
89
+ throw new Error('[timber] key.headers must be an array of header names.');
90
+ }
91
+ for (const name of headers) {
92
+ const problem = headerKeyProblem(name);
93
+ if (problem) throw new Error(`[timber] ${problem}`);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * The canonical key values of one segment in the current request.
99
+ *
100
+ * @param pathParams Every param name on the segment's path, outermost first —
101
+ * the default `segmentParams`.
102
+ * @param params The coerced values of those params.
103
+ */
104
+ export function readKeyValues(
105
+ lifetime: DocumentLifetime,
106
+ pathParams: readonly string[],
107
+ params: CoercedParams
108
+ ): string {
109
+ const { key } = lifetime;
110
+ const names = key.segmentParams ?? pathParams;
111
+ const segmentParams = names.map((name) => [name, canonicalParam(params[name])]);
112
+
113
+ const definition = key.searchParams;
114
+ const searchParams = definition
115
+ ? definition.buildSearchParams(definition.parse(getSearchParams()))
116
+ : null;
117
+
118
+ const jar = key.cookies && key.cookies.length > 0 ? getCookieJar() : null;
119
+ const cookies = (key.cookies ?? []).map((cookie) => [
120
+ cookie.name,
121
+ cookie.codec.serialize(cookie.codec.parse(jar?.get(cookie.name))),
122
+ ]);
123
+
124
+ const requestHeaders = key.headers && key.headers.length > 0 ? getHeaders() : null;
125
+ const headers = (key.headers ?? []).map((name) => [
126
+ name.toLowerCase(),
127
+ requestHeaders?.get(name) ?? null,
128
+ ]);
129
+
130
+ return JSON.stringify([segmentParams, searchParams, cookies, headers]);
131
+ }
132
+
133
+ /**
134
+ * A coerced param as a stable string that keeps every distinct value of the
135
+ * param domain (`shared/param-value.ts`) distinct. Every value is written as a
136
+ * tagged array, so no plain object can spell another kind's tag: `Map` and
137
+ * `Set` (which JSON writes as `{}`), `NaN` and `±Infinity` (which it writes
138
+ * as `null`), `-0`, `bigint`, `undefined` and `Date` each get their own.
139
+ * A `Map` and a plain object keep their insertion order, as a reader sees it.
140
+ */
141
+ function canonicalParam(value: unknown): string {
142
+ return JSON.stringify(tagged(value));
143
+ }
144
+
145
+ function tagged(value: unknown): unknown {
146
+ if (value === undefined) return ['u'];
147
+ if (value === null) return ['n'];
148
+ switch (typeof value) {
149
+ case 'string':
150
+ return ['s', value];
151
+ case 'boolean':
152
+ return ['b', value];
153
+ case 'bigint':
154
+ return ['i', value.toString()];
155
+ case 'number':
156
+ return ['f', Object.is(value, -0) ? '-0' : String(value)];
157
+ case 'object':
158
+ break;
159
+ default:
160
+ return ['?', String(value)];
161
+ }
162
+ if (Array.isArray(value)) return ['a', value.map(tagged)];
163
+ if (value instanceof Date)
164
+ return ['d', Number.isNaN(value.getTime()) ? 'invalid' : value.toISOString()];
165
+ if (value instanceof Map) return ['m', [...value].map(([k, v]) => [tagged(k), tagged(v)])];
166
+ if (value instanceof Set) return ['t', [...value].map(tagged)];
167
+ return ['o', Object.entries(value).map(([k, v]) => [k, tagged(v)])];
168
+ }
@@ -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 SegmentRender } from './outlet-gate.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: SegmentRender;
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);
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)),
127
+ nested: [childrenOutlet],
128
+ document: await this.decision(node, segmentPath, lifetime),
129
+ };
130
+ this.unclaimed = [spec];
131
+ return outletGate(spec);
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 { outletGate, type OutletSpec, type SegmentHashRender } from './segment-hash/outlet.ts';
35
+ import { computeSlotKey, slotChainTreePath } from '../routing/segment-keys.ts';
36
+ import {
37
+ LIVE_ONLY_RENDER,
38
+ outletGate,
39
+ type OutletSpec,
40
+ type SegmentRender,
41
+ } from './segment-lifetime/outlet-gate.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
- ): Promise<React.ReactElement | null> {
99
+ parentTreePath?: string,
100
+ render: SegmentRender = LIVE_ONLY_RENDER
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 slotMatch = interception
97
- ? (findInterceptingMatch(slotNode, interception.targetPathname) ??
98
- findSlotMatch(slotNode, match))
99
- : findSlotMatch(slotNode, match);
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 = computeSlotSegmentPath(slotMatch.chain, parentTreePath);
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 SlotPage = await loadComponent(slotMatch.page);
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(slotNode, slotNode, element, h, scope, denyFallback);
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
- * The full tree path of a slot's matched chain — the key both the ALS slot
248
- * params map and the generated `getSegmentParams` overloads use.
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 Layout = await loadComponent(node.layout);
405
- if (!Layout) return element;
406
- if (!scope || isClientReference(Layout)) return h(Layout, { children: element });
407
-
408
- return h(ScopedSlotLayout, {
409
- layout: Layout as (props: Record<string, unknown>) => unknown,
410
- scope,
411
- denyFallback,
412
- spanAttributes: slotSpanAttributes('timber.segment', node, slotNode),
413
- children: element,
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
  /**
@@ -542,7 +584,7 @@ interface ResolveSlotPropsArgs {
542
584
  parentTreePath: string;
543
585
  /** The request being rendered. */
544
586
  req: Request;
545
- render: SegmentHashRender;
587
+ render: SegmentRender;
546
588
  }
547
589
 
548
590
  /** A layout's slot props, and the outlet of each slot. */
@@ -555,8 +597,8 @@ export interface ResolvedSlots {
555
597
  * Resolve all parallel route slots for a layout, each in its own outlet.
556
598
  *
557
599
  * Every slot is resolved and every slot's access chain runs, on every render.
558
- * Whether a slot's bytes are sent is decided by its outlet's hash, the same
559
- * as any other segment (design/52-segment-hash-dedupe.md).
600
+ * A slot is skipped only through the 'document' segments on its chain
601
+ * (design/53-segment-lifetime.md §"Slots").
560
602
  */
561
603
  export async function resolveSlotProps({
562
604
  segment,
@@ -572,21 +614,22 @@ 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
- props[slotName] = outletGate(spec, render);
632
+ props[slotName] = outletGate(spec);
590
633
  }
591
634
 
592
635
  return { props, outlets };