@timber-js/app 0.2.0-alpha.222 → 0.2.0-alpha.223

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 (354) hide show
  1. package/agent-skill.md +21 -5
  2. package/dist/_chunks/{actions-vBHr2vqd.js → actions-7dTXYJfu.js} +53 -24
  3. package/dist/_chunks/actions-7dTXYJfu.js.map +1 -0
  4. package/dist/_chunks/{als-registry-BZqHCtq-.js → als-registry-DpygwCp0.js} +2 -3
  5. package/dist/_chunks/{als-registry-BZqHCtq-.js.map → als-registry-DpygwCp0.js.map} +1 -1
  6. package/dist/_chunks/{als-slots-BEEIPKYm.js → als-slots-kbQrHTzm.js} +2 -3
  7. package/dist/_chunks/{als-slots-BEEIPKYm.js.map → als-slots-kbQrHTzm.js.map} +1 -1
  8. package/dist/_chunks/{base-path-DaQrzbez.js → base-path-DDIx0FXe.js} +2 -3
  9. package/dist/_chunks/{base-path-DaQrzbez.js.map → base-path-DDIx0FXe.js.map} +1 -1
  10. package/dist/_chunks/{build-manifest-DWppEdLB.js → build-manifest-Y4jl7nwU.js} +2 -3
  11. package/dist/_chunks/{build-manifest-DWppEdLB.js.map → build-manifest-Y4jl7nwU.js.map} +1 -1
  12. package/dist/_chunks/{build-output-helper-RV_BRcF1.js → build-output-helper-B7wWGTfR.js} +14 -10
  13. package/dist/_chunks/build-output-helper-B7wWGTfR.js.map +1 -0
  14. package/dist/_chunks/{cache-api-DdcDLpBj.js → cache-api-TDZ4hlDc.js} +190 -38
  15. package/dist/_chunks/cache-api-TDZ4hlDc.js.map +1 -0
  16. package/dist/_chunks/{canonicalize-BAWkWiKK.js → canonicalize-CqK135BN.js} +29 -4
  17. package/dist/_chunks/{canonicalize-BAWkWiKK.js.map → canonicalize-CqK135BN.js.map} +1 -1
  18. package/dist/_chunks/chains-CwOr3Myj.js +1 -0
  19. package/dist/_chunks/{chains-BchW_AtW.js → chains-Dgm3PrMe.js} +3 -4
  20. package/dist/_chunks/{chains-BchW_AtW.js.map → chains-Dgm3PrMe.js.map} +1 -1
  21. package/dist/_chunks/{classify-IqzMpxMs.js → classify--_kINHQV.js} +4 -5
  22. package/dist/_chunks/{classify-IqzMpxMs.js.map → classify--_kINHQV.js.map} +1 -1
  23. package/dist/_chunks/{cli-check-DQne_YhU.js → cli-check-Dv3f8d2j.js} +5 -6
  24. package/dist/_chunks/{cli-check-DQne_YhU.js.map → cli-check-Dv3f8d2j.js.map} +1 -1
  25. package/dist/_chunks/{cli-context-_mPttGGY.js → cli-context-CbZp32SK.js} +3 -4
  26. package/dist/_chunks/{cli-context-_mPttGGY.js.map → cli-context-CbZp32SK.js.map} +1 -1
  27. package/dist/_chunks/cli-context-n5hmkdla.js +1 -0
  28. package/dist/_chunks/cli-dev-status-prPMLU8G.js +138 -0
  29. package/dist/_chunks/cli-dev-status-prPMLU8G.js.map +1 -0
  30. package/dist/_chunks/cli-init-BoXOYYil.js +196 -0
  31. package/dist/_chunks/cli-init-BoXOYYil.js.map +1 -0
  32. package/dist/_chunks/{cli-schema-sync-BS-RFGE2.js → cli-schema-sync-DIPurq7X.js} +4 -5
  33. package/dist/_chunks/{cli-schema-sync-BS-RFGE2.js.map → cli-schema-sync-DIPurq7X.js.map} +1 -1
  34. package/dist/_chunks/{cli-schema-sync-v872sHms.js → cli-schema-sync-uq72EZmD.js} +1 -1
  35. package/dist/_chunks/{client-dep-entries-BJyP9SIu.js → client-dep-entries-CP7AkMCM.js} +4 -5
  36. package/dist/_chunks/{client-dep-entries-BJyP9SIu.js.map → client-dep-entries-CP7AkMCM.js.map} +1 -1
  37. package/dist/_chunks/{cloudflare-Byxl8FWP.js → cloudflare-B75X6u4O.js} +10 -13
  38. package/dist/_chunks/{cloudflare-Byxl8FWP.js.map → cloudflare-B75X6u4O.js.map} +1 -1
  39. package/dist/_chunks/{codec-registry-oOUxugz3.js → codec-registry-CPc6bjVl.js} +2 -3
  40. package/dist/_chunks/{codec-registry-oOUxugz3.js.map → codec-registry-CPc6bjVl.js.map} +1 -1
  41. package/dist/_chunks/{codegen-Bps1sLKJ.js → codegen-B9oWkWGf.js} +5 -8
  42. package/dist/_chunks/{codegen-Bps1sLKJ.js.map → codegen-B9oWkWGf.js.map} +1 -1
  43. package/dist/_chunks/{convention-lint-VwzrtjIt.js → convention-lint-hZwz5wd4.js} +8 -11
  44. package/dist/_chunks/{convention-lint-VwzrtjIt.js.map → convention-lint-hZwz5wd4.js.map} +1 -1
  45. package/dist/_chunks/dev-discovery-YnabkCKD.js +238 -0
  46. package/dist/_chunks/dev-discovery-YnabkCKD.js.map +1 -0
  47. package/dist/_chunks/{dev-server-BNr5drEO.js → dev-server-C61GWpGg.js} +369 -55
  48. package/dist/_chunks/dev-server-C61GWpGg.js.map +1 -0
  49. package/dist/_chunks/dev-server-CBvvM7Lr.js +1 -0
  50. package/dist/_chunks/{dev-store-BOa304m_.js → dev-store-BvdqtHvK.js} +82 -38
  51. package/dist/_chunks/dev-store-BvdqtHvK.js.map +1 -0
  52. package/dist/_chunks/{dist-DtrJyBbw.js → dist-C1Rjlo6s.js} +3 -5
  53. package/dist/_chunks/{dist-DtrJyBbw.js.map → dist-C1Rjlo6s.js.map} +1 -1
  54. package/dist/_chunks/{error-boundary-Bc8QPZuq.js → error-boundary-DRQXGWCp.js} +20 -27
  55. package/dist/_chunks/{error-boundary-Bc8QPZuq.js.map → error-boundary-DRQXGWCp.js.map} +1 -1
  56. package/dist/_chunks/{fast-hash-C-tVYrLb.js → fast-hash-DddxkU5Y.js} +2 -3
  57. package/dist/_chunks/{fast-hash-C-tVYrLb.js.map → fast-hash-DddxkU5Y.js.map} +1 -1
  58. package/dist/_chunks/{flight-source-node-BdHUOUqg.js → flight-source-node-0Tp6evlz.js} +6 -8
  59. package/dist/_chunks/flight-source-node-0Tp6evlz.js.map +1 -0
  60. package/dist/_chunks/{format-BKclgVbk.js → format-DuPOoXUP.js} +2 -3
  61. package/dist/_chunks/{format-BKclgVbk.js.map → format-DuPOoXUP.js.map} +1 -1
  62. package/dist/_chunks/{fs-identity-BRKuL215.js → fs-identity-BmQ_Agg-.js} +3 -5
  63. package/dist/_chunks/{fs-identity-BRKuL215.js.map → fs-identity-BmQ_Agg-.js.map} +1 -1
  64. package/dist/_chunks/{global-context-B9PFncvb.js → global-context-DbxNWeBP.js} +2 -3
  65. package/dist/_chunks/{global-context-B9PFncvb.js.map → global-context-DbxNWeBP.js.map} +1 -1
  66. package/dist/_chunks/{graph-cache-CYiUS2aS.js → graph-cache-B1LAg4t7.js} +5 -89
  67. package/dist/_chunks/graph-cache-B1LAg4t7.js.map +1 -0
  68. package/dist/_chunks/{href-validation-BIrxavIy.js → href-validation-CEZy1V-k.js} +4 -7
  69. package/dist/_chunks/{href-validation-BIrxavIy.js.map → href-validation-CEZy1V-k.js.map} +1 -1
  70. package/dist/_chunks/{json-lossy-check-C3Sht92C.js → json-lossy-check-DVkLUlfC.js} +3 -4
  71. package/dist/_chunks/{json-lossy-check-C3Sht92C.js.map → json-lossy-check-DVkLUlfC.js.map} +1 -1
  72. package/dist/_chunks/{live-graph-DEu_GWbc.js → live-graph-BcVjQ1Te.js} +6 -7
  73. package/dist/_chunks/{live-graph-DEu_GWbc.js.map → live-graph-BcVjQ1Te.js.map} +1 -1
  74. package/dist/_chunks/{logger-CI_hThfy.js → logger-CWk44DLp.js} +89 -47
  75. package/dist/_chunks/logger-CWk44DLp.js.map +1 -0
  76. package/dist/_chunks/{metadata-routes-B3XJNyIH.js → metadata-routes-BL26HCDd.js} +2 -3
  77. package/dist/_chunks/{metadata-routes-B3XJNyIH.js.map → metadata-routes-BL26HCDd.js.map} +1 -1
  78. package/dist/_chunks/{navigation-root-BQfo1-kG.js → navigation-root-M3B2ZrdO.js} +6 -10
  79. package/dist/_chunks/{navigation-root-BQfo1-kG.js.map → navigation-root-M3B2ZrdO.js.map} +1 -1
  80. package/dist/_chunks/{node-response-bF0bKoig.js → node-response-B9aviPDa.js} +43 -9
  81. package/dist/_chunks/node-response-B9aviPDa.js.map +1 -0
  82. package/dist/_chunks/{param-value-C8TNYchQ.js → param-value-DqlGfF57.js} +2 -3
  83. package/dist/_chunks/{param-value-C8TNYchQ.js.map → param-value-DqlGfF57.js.map} +1 -1
  84. package/dist/_chunks/{plugin-context-uDHFqHHJ.js → plugin-context-BfSRKJfz.js} +1 -1
  85. package/dist/_chunks/{plugin-context-DxMMvjUt.js → plugin-context-FCkaNLUB.js} +4 -6
  86. package/dist/_chunks/plugin-context-FCkaNLUB.js.map +1 -0
  87. package/dist/_chunks/{poison-rules-DoEhbqaY.js → poison-rules-Bmz-lCPi.js} +2 -3
  88. package/dist/_chunks/{poison-rules-DoEhbqaY.js.map → poison-rules-Bmz-lCPi.js.map} +1 -1
  89. package/dist/_chunks/{poison-scan-DTWIfNgD.js → poison-scan-DJYxZc_7.js} +4 -5
  90. package/dist/_chunks/{poison-scan-DTWIfNgD.js.map → poison-scan-DJYxZc_7.js.map} +1 -1
  91. package/dist/_chunks/{purge-store-WZaxu-3m.js → purge-store-8BqLAYZ1.js} +2 -3
  92. package/dist/_chunks/{purge-store-WZaxu-3m.js.map → purge-store-8BqLAYZ1.js.map} +1 -1
  93. package/dist/_chunks/{render-timeout-Ln_u7fX-.js → render-timeout-MrrqD1wd.js} +2 -3
  94. package/dist/_chunks/{render-timeout-Ln_u7fX-.js.map → render-timeout-MrrqD1wd.js.map} +1 -1
  95. package/dist/_chunks/{resolve-schema-CkAInout.js → resolve-schema-B-aCuTu3.js} +3 -4
  96. package/dist/_chunks/{resolve-schema-CkAInout.js.map → resolve-schema-B-aCuTu3.js.map} +1 -1
  97. package/dist/_chunks/{rsc-cache-key-ClUiXQnK.js → rsc-cache-key-D0cb0Gmc.js} +2 -3
  98. package/dist/_chunks/{rsc-cache-key-ClUiXQnK.js.map → rsc-cache-key-D0cb0Gmc.js.map} +1 -1
  99. package/dist/_chunks/{rsc-media-type-DDc7duTD.js → rsc-media-type-m8jz9u6_.js} +2 -3
  100. package/dist/_chunks/{rsc-media-type-DDc7duTD.js.map → rsc-media-type-m8jz9u6_.js.map} +1 -1
  101. package/dist/_chunks/{rsc-payload-path-dffcs4jp.js → rsc-payload-path-EphpDB-J.js} +2 -3
  102. package/dist/_chunks/{rsc-payload-path-dffcs4jp.js.map → rsc-payload-path-EphpDB-J.js.map} +1 -1
  103. package/dist/_chunks/{scan-BoP17W3w.js → scan-CyizcBiX.js} +2 -3
  104. package/dist/_chunks/{scan-BoP17W3w.js.map → scan-CyizcBiX.js.map} +1 -1
  105. package/dist/_chunks/{scanner-C8fdKvKG.js → scanner-CJC-ScJU.js} +15 -23
  106. package/dist/_chunks/{scanner-C8fdKvKG.js.map → scanner-CJC-ScJU.js.map} +1 -1
  107. package/dist/_chunks/{schema-bridge-DpOmvZlI.js → schema-bridge-DyRs3cqy.js} +2 -3
  108. package/dist/_chunks/{schema-bridge-DpOmvZlI.js.map → schema-bridge-DyRs3cqy.js.map} +1 -1
  109. package/dist/_chunks/{segment-classify-C539Pa2O.js → segment-classify-Ho8jXWeC.js} +3 -5
  110. package/dist/_chunks/{segment-classify-C539Pa2O.js.map → segment-classify-Ho8jXWeC.js.map} +1 -1
  111. package/dist/_chunks/{segment-context-D3DNxKFq.js → segment-context-CYiGTi3K.js} +4 -6
  112. package/dist/_chunks/{segment-context-D3DNxKFq.js.map → segment-context-CYiGTi3K.js.map} +1 -1
  113. package/dist/_chunks/{segment-keys-D5hu1hz4.js → segment-keys-Y60KNc8C.js} +2 -3
  114. package/dist/_chunks/{segment-keys-D5hu1hz4.js.map → segment-keys-Y60KNc8C.js.map} +1 -1
  115. package/dist/_chunks/{singleflight-BeVMMKi0.js → singleflight-BChPMjwH.js} +2 -3
  116. package/dist/_chunks/{singleflight-BeVMMKi0.js.map → singleflight-BChPMjwH.js.map} +1 -1
  117. package/dist/_chunks/{sizeof-CO3dk0V1.js → sizeof-DG4W40lv.js} +3 -4
  118. package/dist/_chunks/{sizeof-CO3dk0V1.js.map → sizeof-DG4W40lv.js.map} +1 -1
  119. package/dist/_chunks/{ssr-data-nA3I70_n.js → ssr-data-9hPtcNOr.js} +3 -4
  120. package/dist/_chunks/{ssr-data-nA3I70_n.js.map → ssr-data-9hPtcNOr.js.map} +1 -1
  121. package/dist/_chunks/{state-BhNGPsdi.js → state-B-EBjeER.js} +2 -3
  122. package/dist/_chunks/{state-BhNGPsdi.js.map → state-B-EBjeER.js.map} +1 -1
  123. package/dist/_chunks/{status-page-marker-BRX9Ib-d.js → status-page-marker-XIQXlTOb.js} +8 -13
  124. package/dist/_chunks/{status-page-marker-BRX9Ib-d.js.map → status-page-marker-XIQXlTOb.js.map} +1 -1
  125. package/dist/_chunks/{tree-match-6yihorhk.js → tree-match-Bqdr9szG.js} +2 -3
  126. package/dist/_chunks/{tree-match-6yihorhk.js.map → tree-match-Bqdr9szG.js.map} +1 -1
  127. package/dist/_chunks/{use-query-states-I3JMng6J.js → use-query-states-pkDV-jSg.js} +4 -7
  128. package/dist/_chunks/{use-query-states-I3JMng6J.js.map → use-query-states-pkDV-jSg.js.map} +1 -1
  129. package/dist/_chunks/{walkers-BqzxnwGC.js → walkers-DIE203ir.js} +6 -8
  130. package/dist/_chunks/{walkers-BqzxnwGC.js.map → walkers-DIE203ir.js.map} +1 -1
  131. package/dist/_chunks/{write-file-atomic-D1qWqHb4.js → write-file-atomic-DW8m_Atv.js} +2 -3
  132. package/dist/_chunks/{write-file-atomic-D1qWqHb4.js.map → write-file-atomic-DW8m_Atv.js.map} +1 -1
  133. package/dist/adapters/build-output-helper.d.ts +10 -1
  134. package/dist/adapters/build-output-helper.d.ts.map +1 -1
  135. package/dist/adapters/cloudflare-dev.js +2 -3
  136. package/dist/adapters/cloudflare-kv-cache.js +3 -4
  137. package/dist/adapters/cloudflare.d.ts.map +1 -1
  138. package/dist/adapters/cloudflare.js +1 -1
  139. package/dist/adapters/nitro-presets.d.ts +6 -0
  140. package/dist/adapters/nitro-presets.d.ts.map +1 -1
  141. package/dist/adapters/nitro-preview.d.ts.map +1 -1
  142. package/dist/adapters/nitro.d.ts.map +1 -1
  143. package/dist/adapters/nitro.js +94 -57
  144. package/dist/adapters/nitro.js.map +1 -1
  145. package/dist/analyze/crawl-entry.js +7 -9
  146. package/dist/analyze/crawl-entry.js.map +1 -1
  147. package/dist/analyze/graph-command.d.ts.map +1 -1
  148. package/dist/analyze/graph-command.js +19 -105
  149. package/dist/analyze/graph-command.js.map +1 -1
  150. package/dist/cache/index.js +3 -3
  151. package/dist/cache/key-discipline.d.ts +61 -0
  152. package/dist/cache/key-discipline.d.ts.map +1 -0
  153. package/dist/cache/stores/cloudflare-kv.js +1 -2
  154. package/dist/cache/stores/memory.js +2 -3
  155. package/dist/cache/stores/redis.js +1 -2
  156. package/dist/cache/stores/vercel.js +1 -2
  157. package/dist/cache/timber-cache.d.ts +5 -1
  158. package/dist/cache/timber-cache.d.ts.map +1 -1
  159. package/dist/cdn/cloudflare-purge.js +1 -2
  160. package/dist/cdn/fastly-purge.js +1 -2
  161. package/dist/cdn/index.js +2 -3
  162. package/dist/cdn/workers-cache-purge.js +3 -5
  163. package/dist/cdn/workers-cache-purge.js.map +1 -1
  164. package/dist/cli-dev-status.d.ts +75 -0
  165. package/dist/cli-dev-status.d.ts.map +1 -0
  166. package/dist/cli-init.d.ts +72 -0
  167. package/dist/cli-init.d.ts.map +1 -0
  168. package/dist/cli.d.ts +4 -12
  169. package/dist/cli.d.ts.map +1 -1
  170. package/dist/cli.js +27 -54
  171. package/dist/cli.js.map +1 -1
  172. package/dist/client/error-boundary.d.ts.map +1 -1
  173. package/dist/client/error-boundary.js +1 -1
  174. package/dist/client/index.js +22 -34
  175. package/dist/client/index.js.map +1 -1
  176. package/dist/client/internal.js +13 -18
  177. package/dist/client/internal.js.map +1 -1
  178. package/dist/client/use-cookie.d.ts +18 -5
  179. package/dist/client/use-cookie.d.ts.map +1 -1
  180. package/dist/codec.js +2 -3
  181. package/dist/config-types.d.ts +22 -5
  182. package/dist/config-types.d.ts.map +1 -1
  183. package/dist/config-validation.d.ts.map +1 -1
  184. package/dist/cookies/define-cookie.d.ts.map +1 -1
  185. package/dist/cookies/index.js +40 -67
  186. package/dist/cookies/index.js.map +1 -1
  187. package/dist/cookies/json-cookie.d.ts +4 -4
  188. package/dist/index.js +266 -229
  189. package/dist/index.js.map +1 -1
  190. package/dist/params/index.js +3 -4
  191. package/dist/plugin-context.d.ts +7 -0
  192. package/dist/plugin-context.d.ts.map +1 -1
  193. package/dist/plugins/dev-discovery.d.ts +69 -5
  194. package/dist/plugins/dev-discovery.d.ts.map +1 -1
  195. package/dist/plugins/dev-hostname.d.ts +152 -0
  196. package/dist/plugins/dev-hostname.d.ts.map +1 -0
  197. package/dist/plugins/dev-server.d.ts +5 -1
  198. package/dist/plugins/dev-server.d.ts.map +1 -1
  199. package/dist/plugins/dev-store-clear.d.ts +59 -4
  200. package/dist/plugins/dev-store-clear.d.ts.map +1 -1
  201. package/dist/plugins/graph-endpoint.d.ts +4 -2
  202. package/dist/plugins/graph-endpoint.d.ts.map +1 -1
  203. package/dist/plugins/prebuilt.d.ts.map +1 -1
  204. package/dist/routing/index.js +4 -4
  205. package/dist/rsc-runtime/rsc.d.ts +2 -1
  206. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  207. package/dist/rsc-runtime/server-references.d.ts +8 -0
  208. package/dist/rsc-runtime/server-references.d.ts.map +1 -0
  209. package/dist/search-params/index.js +5 -7
  210. package/dist/search-params/index.js.map +1 -1
  211. package/dist/server/access-gate.d.ts +12 -0
  212. package/dist/server/access-gate.d.ts.map +1 -1
  213. package/dist/server/canonicalize.d.ts +21 -0
  214. package/dist/server/canonicalize.d.ts.map +1 -1
  215. package/dist/server/cookie-context.d.ts +8 -1
  216. package/dist/server/cookie-context.d.ts.map +1 -1
  217. package/dist/server/flight-source-node.d.ts.map +1 -1
  218. package/dist/server/flight-source.d.ts.map +1 -1
  219. package/dist/server/index.d.ts +1 -1
  220. package/dist/server/index.d.ts.map +1 -1
  221. package/dist/server/index.js +8 -13
  222. package/dist/server/index.js.map +1 -1
  223. package/dist/server/interception-gates.d.ts +49 -0
  224. package/dist/server/interception-gates.d.ts.map +1 -0
  225. package/dist/server/internal.js +1061 -943
  226. package/dist/server/internal.js.map +1 -1
  227. package/dist/server/logger.d.ts +17 -0
  228. package/dist/server/logger.d.ts.map +1 -1
  229. package/dist/server/param-coercion.d.ts +8 -0
  230. package/dist/server/param-coercion.d.ts.map +1 -1
  231. package/dist/server/pipeline-interception.d.ts +34 -4
  232. package/dist/server/pipeline-interception.d.ts.map +1 -1
  233. package/dist/server/pipeline-metadata-route.d.ts +24 -0
  234. package/dist/server/pipeline-metadata-route.d.ts.map +1 -0
  235. package/dist/server/pipeline-metadata.d.ts +3 -2
  236. package/dist/server/pipeline-metadata.d.ts.map +1 -1
  237. package/dist/server/pipeline-phases.d.ts +9 -3
  238. package/dist/server/pipeline-phases.d.ts.map +1 -1
  239. package/dist/server/pipeline.d.ts +18 -0
  240. package/dist/server/pipeline.d.ts.map +1 -1
  241. package/dist/server/prebuilt/dev-store.d.ts +68 -22
  242. package/dist/server/prebuilt/dev-store.d.ts.map +1 -1
  243. package/dist/server/prebuilt/overlay.d.ts +8 -0
  244. package/dist/server/prebuilt/overlay.d.ts.map +1 -1
  245. package/dist/server/prebuilt-runtime.d.ts.map +1 -1
  246. package/dist/server/primitives.d.ts +13 -0
  247. package/dist/server/primitives.d.ts.map +1 -1
  248. package/dist/server/render-utils.d.ts +21 -0
  249. package/dist/server/render-utils.d.ts.map +1 -1
  250. package/dist/server/request-context.d.ts +14 -0
  251. package/dist/server/request-context.d.ts.map +1 -1
  252. package/dist/server/route-element-builder.d.ts.map +1 -1
  253. package/dist/server/route-handler.d.ts +7 -0
  254. package/dist/server/route-handler.d.ts.map +1 -1
  255. package/dist/server/route-matcher.d.ts +14 -3
  256. package/dist/server/route-matcher.d.ts.map +1 -1
  257. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  258. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  259. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  260. package/dist/server/signal-identity.d.ts +6 -0
  261. package/dist/server/signal-identity.d.ts.map +1 -1
  262. package/dist/server/traced-access.d.ts +18 -0
  263. package/dist/server/traced-access.d.ts.map +1 -0
  264. package/dist/server/tracing.d.ts.map +1 -1
  265. package/dist/server/types.d.ts +5 -4
  266. package/dist/server/types.d.ts.map +1 -1
  267. package/dist/shims/font-google.js +1 -2
  268. package/dist/shims/font-local.js +1 -2
  269. package/dist/shims/headers.d.ts +11 -4
  270. package/dist/shims/headers.d.ts.map +1 -1
  271. package/docs/api/30-api-server.mdx +3 -1
  272. package/docs/api/32-api-cache.mdx +1 -1
  273. package/docs/api/34-api-config.mdx +22 -0
  274. package/docs/api/36-cli.mdx +72 -6
  275. package/docs/learn/01-quick-start.mdx +1 -1
  276. package/docs/learn/06-typed-params.mdx +2 -2
  277. package/docs/learn/10-caching.mdx +26 -5
  278. package/llms.txt +1 -1
  279. package/package.json +12 -12
  280. package/src/adapters/build-output-helper.ts +26 -4
  281. package/src/adapters/cloudflare.ts +1 -0
  282. package/src/adapters/nitro-presets.ts +15 -0
  283. package/src/adapters/nitro-preview.ts +66 -34
  284. package/src/adapters/nitro.ts +14 -6
  285. package/src/analyze/graph-command.ts +25 -133
  286. package/src/cache/key-discipline.ts +218 -0
  287. package/src/cache/timber-cache.ts +42 -5
  288. package/src/cli-dev-status.ts +196 -0
  289. package/src/cli-init.ts +278 -0
  290. package/src/cli.ts +33 -79
  291. package/src/client/error-boundary.tsx +19 -2
  292. package/src/client/use-cookie.ts +33 -21
  293. package/src/config-types.ts +22 -5
  294. package/src/config-validation.ts +17 -0
  295. package/src/cookies/define-cookie.ts +10 -46
  296. package/src/cookies/json-cookie.ts +4 -4
  297. package/src/plugin-context.ts +7 -0
  298. package/src/plugins/dev-discovery.ts +216 -6
  299. package/src/plugins/dev-hostname.ts +322 -0
  300. package/src/plugins/dev-server.ts +96 -37
  301. package/src/plugins/dev-store-clear.ts +105 -7
  302. package/src/plugins/graph-endpoint.ts +15 -3
  303. package/src/plugins/prebuilt.ts +9 -0
  304. package/src/rsc-runtime/rsc.ts +7 -3
  305. package/src/rsc-runtime/server-references.ts +73 -0
  306. package/src/rsc-runtime/vendor-types.d.ts +9 -0
  307. package/src/server/access-gate.tsx +32 -20
  308. package/src/server/action-handler.ts +40 -34
  309. package/src/server/canonicalize.ts +27 -0
  310. package/src/server/cookie-context.ts +11 -3
  311. package/src/server/flight-source-node.ts +5 -2
  312. package/src/server/flight-source.ts +4 -3
  313. package/src/server/index.ts +6 -1
  314. package/src/server/interception-gates.ts +94 -0
  315. package/src/server/logger.ts +23 -0
  316. package/src/server/param-coercion.ts +22 -0
  317. package/src/server/pipeline-interception.ts +64 -4
  318. package/src/server/pipeline-metadata-route.ts +242 -0
  319. package/src/server/pipeline-metadata.ts +7 -5
  320. package/src/server/pipeline-phases.ts +71 -131
  321. package/src/server/pipeline.ts +20 -2
  322. package/src/server/prebuilt/dev-store.ts +113 -34
  323. package/src/server/prebuilt/overlay.ts +18 -0
  324. package/src/server/prebuilt-runtime.ts +43 -44
  325. package/src/server/primitives.ts +14 -0
  326. package/src/server/render-utils.ts +25 -0
  327. package/src/server/request-context.ts +27 -3
  328. package/src/server/route-element-builder.ts +15 -2
  329. package/src/server/route-handler.ts +3 -2
  330. package/src/server/route-matcher.ts +48 -33
  331. package/src/server/rsc-entry/api-handler.ts +2 -33
  332. package/src/server/rsc-entry/index.ts +8 -3
  333. package/src/server/rsc-entry/rsc-stream.ts +7 -1
  334. package/src/server/signal-identity.ts +30 -12
  335. package/src/server/traced-access.ts +50 -0
  336. package/src/server/tracing.ts +18 -1
  337. package/src/server/types.ts +5 -4
  338. package/src/shims/headers.ts +12 -4
  339. package/dist/_chunks/actions-vBHr2vqd.js.map +0 -1
  340. package/dist/_chunks/build-output-helper-RV_BRcF1.js.map +0 -1
  341. package/dist/_chunks/cache-api-DdcDLpBj.js.map +0 -1
  342. package/dist/_chunks/chains-B8TCLved.js +0 -1
  343. package/dist/_chunks/cli-context-BJQB6rtF.js +0 -1
  344. package/dist/_chunks/dev-server-BNr5drEO.js.map +0 -1
  345. package/dist/_chunks/dev-server-CUg7Mqh_.js +0 -1
  346. package/dist/_chunks/dev-store-BOa304m_.js.map +0 -1
  347. package/dist/_chunks/flight-source-node-BdHUOUqg.js.map +0 -1
  348. package/dist/_chunks/graph-cache-CYiUS2aS.js.map +0 -1
  349. package/dist/_chunks/logger-CI_hThfy.js.map +0 -1
  350. package/dist/_chunks/node-response-bF0bKoig.js.map +0 -1
  351. package/dist/_chunks/plugin-context-DxMMvjUt.js.map +0 -1
  352. package/dist/server/prebuilt/key-discipline.d.ts +0 -52
  353. package/dist/server/prebuilt/key-discipline.d.ts.map +0 -1
  354. package/src/server/prebuilt/key-discipline.ts +0 -122
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Per-app dev hostnames — print and open `<name>.localhost:<port>`.
3
+ *
4
+ * Cookies are not scoped by port, so every app served on `localhost` shares
5
+ * one cookie jar: two apps on :3000 and :3001 overwrite each other's
6
+ * sessions, and service workers stuck to `localhost:3000` carry over to
7
+ * whichever project next gets that port. Browsers resolve
8
+ * `*.localhost` (at any depth) to loopback with no DNS or `/etc/hosts` setup,
9
+ * so giving each app its own name gives it its own cookie jar.
10
+ *
11
+ * This only changes the URL Vite prints, opens, and records for discovery.
12
+ * Nothing is proxied, no `Host` is rewritten, and plain `localhost:<port>`
13
+ * keeps working. Vite's host check already accepts `*.localhost`.
14
+ *
15
+ * See design/21-dev-server.md §"Dev Hostnames" (TIM-1613).
16
+ */
17
+
18
+ import { X509Certificate } from 'node:crypto';
19
+ import { readFileSync } from 'node:fs';
20
+ import { basename, join, resolve } from 'node:path';
21
+
22
+ const LOCALHOST = 'localhost';
23
+ const LOCALHOST_SUFFIX = `.${LOCALHOST}`;
24
+
25
+ /** RFC 1035 label limit. */
26
+ const MAX_LABEL_LENGTH = 63;
27
+
28
+ /** RFC 1035 name limit, `.localhost` included. */
29
+ const MAX_HOSTNAME_LENGTH = 253;
30
+
31
+ /**
32
+ * Package names that say nothing about the app: the create-timber-app
33
+ * default (`packages/create-timber-app/src/index.ts`) and the generic names
34
+ * people leave in templates. They would put every unrenamed app on the same
35
+ * hostname, and so the same cookie jar, which is exactly what this
36
+ * feature is for avoiding. The directory name is used instead.
37
+ */
38
+ const PLACEHOLDER_PACKAGE_NAMES = new Set(['app', 'my-app', 'my-timber-app']);
39
+
40
+ const LABEL_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
41
+
42
+ /**
43
+ * Reduce arbitrary text to one DNS label: lowercase, anything outside
44
+ * `[a-z0-9-]` becomes `-`, runs of `-` collapse, no leading or trailing
45
+ * `-`, at most 63 characters. May return '' when nothing usable is left.
46
+ */
47
+ export function sanitizeLabel(raw: string): string {
48
+ return raw
49
+ .toLowerCase()
50
+ .replace(/[^a-z0-9-]+/g, '-')
51
+ .replace(/-{2,}/g, '-')
52
+ .replace(/^-+/, '')
53
+ .slice(0, MAX_LABEL_LENGTH)
54
+ .replace(/-+$/, '');
55
+ }
56
+
57
+ /**
58
+ * Labels for a package name, most specific first: `@acme/web` →
59
+ * `['web', 'acme']` (so `web.acme.localhost`), `example-blog` →
60
+ * `['example-blog']`. Placeholders and non-strings give `[]`.
61
+ */
62
+ function packageNameLabels(name: unknown): string[] {
63
+ if (typeof name !== 'string') return [];
64
+ if (PLACEHOLDER_PACKAGE_NAMES.has(name.trim().toLowerCase())) return [];
65
+ const scoped = /^@([^/]+)\/(.+)$/.exec(name);
66
+ const parts = scoped ? [scoped[2], scoped[1]] : [name];
67
+ return parts.map(sanitizeLabel).filter(Boolean);
68
+ }
69
+
70
+ /**
71
+ * Why a `dev.hostname` value is unusable, or null when it is fine. Accepts
72
+ * `false` (opt out: keep plain `localhost`) or a dot-separated sequence of
73
+ * DNS labels, case-insensitively, with or without a trailing `.localhost`.
74
+ */
75
+ export function devHostnameError(value: unknown): string | null {
76
+ if (value === false) return null;
77
+ if (typeof value !== 'string') {
78
+ return `must be a string like "blog" or false, got ${JSON.stringify(value)}.`;
79
+ }
80
+ const labels = stripLocalhost(value.toLowerCase());
81
+ if (labels === '') {
82
+ return `${JSON.stringify(value)} names no app. Use a name like "blog", or false to keep plain localhost.`;
83
+ }
84
+ const bad = labels.split('.').find((label) => !LABEL_RE.test(label));
85
+ if (bad !== undefined) {
86
+ return (
87
+ `${JSON.stringify(value)} is not a valid hostname: label ${JSON.stringify(bad)} must be ` +
88
+ '1-63 characters of a-z, 0-9 and "-", not starting or ending with "-".'
89
+ );
90
+ }
91
+ if (labels.length + LOCALHOST_SUFFIX.length > MAX_HOSTNAME_LENGTH) {
92
+ return `${JSON.stringify(value)} is longer than a hostname can be (253 characters with .localhost).`;
93
+ }
94
+ return null;
95
+ }
96
+
97
+ function stripLocalhost(name: string): string {
98
+ if (name === LOCALHOST) return '';
99
+ return name.endsWith(LOCALHOST_SUFFIX) ? name.slice(0, -LOCALHOST_SUFFIX.length) : name;
100
+ }
101
+
102
+ export interface DevHostnameSource {
103
+ /** `dev.hostname` from timber.config.ts. */
104
+ override?: string | false;
105
+ /** `name` from the app's package.json, if it has one. */
106
+ packageName?: unknown;
107
+ /** The app directory's own name. */
108
+ dirName: string;
109
+ }
110
+
111
+ /**
112
+ * The dev hostname for an app. In order:
113
+ *
114
+ * 1. `dev.hostname`, when set (`false` → plain `localhost`). An invalid value
115
+ * throws; config validation reports it as fatal before this runs.
116
+ * 2. package.json `name`, unless it is a placeholder. Preferred over the
117
+ * directory because it is stable across clones and worktrees, so OAuth
118
+ * callback URLs registered against it keep working, and because monorepo
119
+ * directories are generic (`apps/web` everywhere).
120
+ * 3. The directory name.
121
+ * 4. Plain `localhost`, when nothing usable is left after sanitizing.
122
+ */
123
+ export function deriveDevHostname(source: DevHostnameSource): string {
124
+ const { override } = source;
125
+ if (override === false) return LOCALHOST;
126
+ if (override !== undefined) {
127
+ const error = devHostnameError(override);
128
+ if (error) throw new Error(`[timber] dev.hostname ${error}`);
129
+ return `${stripLocalhost(override.toLowerCase())}${LOCALHOST_SUFFIX}`;
130
+ }
131
+ let labels = packageNameLabels(source.packageName);
132
+ if (labels.length === 0) labels = [sanitizeLabel(source.dirName)].filter(Boolean);
133
+ return labels.length === 0 ? LOCALHOST : `${labels.join('.')}${LOCALHOST_SUFFIX}`;
134
+ }
135
+
136
+ /**
137
+ * `deriveDevHostname` for the app in `appDir` — the directory its
138
+ * `.timber/` lives in (`devRecordRoot`), where its package.json is. A
139
+ * missing or unreadable package.json falls through to the directory name.
140
+ */
141
+ export function resolveDevHostname(appDir: string, override: string | false | undefined): string {
142
+ let packageName: unknown;
143
+ try {
144
+ packageName = (
145
+ JSON.parse(readFileSync(join(appDir, 'package.json'), 'utf8')) as {
146
+ name?: unknown;
147
+ }
148
+ ).name;
149
+ } catch {
150
+ packageName = undefined;
151
+ }
152
+ return deriveDevHostname({ override, packageName, dirName: basename(appDir) });
153
+ }
154
+
155
+ /**
156
+ * A `cert` entry as Vite reads it (`readFileIfExists` in its
157
+ * `resolveHttpsConfig`): a string is first tried as a file path, resolved
158
+ * against the cwd, and is PEM text only when no such file can be read.
159
+ * `config.server.https` keeps the raw option, so the path is read here too.
160
+ */
161
+ function certBytes(entry: unknown): string | Uint8Array | null {
162
+ if (entry instanceof Uint8Array) return entry;
163
+ if (typeof entry !== 'string') return null;
164
+ try {
165
+ return readFileSync(resolve(entry));
166
+ } catch {
167
+ return entry;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Whether a TLS `cert` option (PEM string or Buffer, a path to one, or an
173
+ * array of them — Node's `tls` shape plus Vite's paths) names `hostname`.
174
+ * A `pfx`-only config has no `cert` and so keeps `localhost`. An https dev server prints the
175
+ * named URL only when it does: a trusted certificate issued for `localhost`
176
+ * alone (mkcert's default) would turn a working URL into a certificate error.
177
+ */
178
+ export function certCoversHostname(cert: unknown, hostname: string): boolean {
179
+ const pems = Array.isArray(cert) ? cert : [cert];
180
+ return pems.some((entry) => {
181
+ const pem = certBytes(entry);
182
+ if (pem === null) return false;
183
+ try {
184
+ return new X509Certificate(pem).checkHost(hostname) !== undefined;
185
+ } catch {
186
+ return false;
187
+ }
188
+ });
189
+ }
190
+
191
+ /**
192
+ * The hostname to print for this server, after the https check. `https` is
193
+ * Vite's resolved `server.https` (undefined for plain http).
194
+ */
195
+ export function effectiveDevHostname(
196
+ hostname: string,
197
+ https: { cert?: unknown } | undefined
198
+ ): string {
199
+ if (hostname === LOCALHOST || !https) return hostname;
200
+ return certCoversHostname(https.cert, hostname) ? hostname : LOCALHOST;
201
+ }
202
+
203
+ /**
204
+ * Vite's `server.resolvedUrls` shape — the URLs it prints under Local and
205
+ * Network and picks from for `server.open`.
206
+ */
207
+ export interface ResolvedServerUrls {
208
+ local: string[];
209
+ network: string[];
210
+ }
211
+
212
+ /**
213
+ * Rename the `localhost` entries of `urls.local` to `hostname`. Only those:
214
+ * an explicit loopback IP (`host: '127.0.0.1'`) is what the developer asked
215
+ * to see, certificate-derived names already name a host, and network URLs
216
+ * are other machines' way in. Idempotent: a renamed URL is no longer a
217
+ * `localhost` URL.
218
+ */
219
+ export function withDevHostname<T extends ResolvedServerUrls>(urls: T, hostname: string): T {
220
+ if (hostname === LOCALHOST) return urls;
221
+ const local = urls.local.map((href) => {
222
+ const url = new URL(href);
223
+ if (url.hostname !== LOCALHOST) return href;
224
+ url.hostname = hostname;
225
+ return url.href;
226
+ });
227
+ return { ...urls, local: [...new Set(local)] };
228
+ }
229
+
230
+ /**
231
+ * The same URL through plain `localhost`: what a non-browser HTTP client can
232
+ * reach. Browsers and curl resolve `*.localhost` themselves, but Node, Python
233
+ * and other clients ask the OS, and not every resolver (glibc without
234
+ * systemd-resolved) maps `*.localhost` to loopback. The server answers both
235
+ * names, so only the hostname changes. Other URLs are returned unchanged.
236
+ *
237
+ * Under https the swap also has to survive TLS hostname verification: a
238
+ * certificate issued for `blog.localhost` alone fails for `localhost`
239
+ * (`ERR_TLS_CERT_ALTNAME_INVALID`), so the named URL is kept unless the
240
+ * certificate covers `localhost` too. `https` is Vite's `server.https`.
241
+ */
242
+ export function loopbackUrl(href: string, https: { cert?: unknown } | undefined): string {
243
+ const url = new URL(href);
244
+ if (!url.hostname.endsWith(LOCALHOST_SUFFIX)) return href;
245
+ if (url.protocol === 'https:' && !certCoversHostname(https?.cert, LOCALHOST)) return href;
246
+ url.hostname = LOCALHOST;
247
+ return url.href;
248
+ }
249
+
250
+ /**
251
+ * The URL a server is opened at, after the rename: Vite's own choice, as its
252
+ * `getServerUrlByHost` makes it for `server.open` — the first URL containing
253
+ * a string `server.host`, else `local[0]`, else `network[0]`. The discovery
254
+ * record stores this, so `timber dev status` reports the URL Vite opens.
255
+ */
256
+ export function primaryServerUrl(
257
+ urls: ResolvedServerUrls | null | undefined,
258
+ hostname: string,
259
+ serverHost: string | boolean | undefined
260
+ ): string | undefined {
261
+ if (!urls) return undefined;
262
+ const named = withDevHostname(urls, hostname);
263
+ const all = [...named.local, ...named.network];
264
+ const byHost =
265
+ typeof serverHost === 'string' ? all.find((url) => url.includes(serverHost)) : undefined;
266
+ return byHost ?? named.local[0] ?? named.network[0];
267
+ }
268
+
269
+ /** The URLs a discovery record advertises. */
270
+ export interface AdvertisedUrls {
271
+ /** What the server printed and opens (`primaryServerUrl`). */
272
+ url: string;
273
+ /** The same server for non-browser HTTP clients (`loopbackUrl`). */
274
+ loopbackUrl: string;
275
+ }
276
+
277
+ /**
278
+ * The record's URLs, computed by the server, which alone knows its
279
+ * certificate. `server` is Vite's resolved `server` config.
280
+ */
281
+ export function advertisedUrls(
282
+ urls: ResolvedServerUrls | null | undefined,
283
+ hostname: string,
284
+ server: { host?: string | boolean; https?: { cert?: unknown } } | undefined
285
+ ): AdvertisedUrls | undefined {
286
+ const url = primaryServerUrl(urls, hostname, server?.host);
287
+ return url === undefined ? undefined : { url, loopbackUrl: loopbackUrl(url, server?.https) };
288
+ }
289
+
290
+ /** The slice of `ViteDevServer` the rename needs. */
291
+ interface DevHostnameServer {
292
+ httpServer: { on(event: 'listening', listener: () => void): unknown } | null;
293
+ resolvedUrls: ResolvedServerUrls | null;
294
+ config: { server?: { https?: { cert?: unknown } } };
295
+ }
296
+
297
+ /**
298
+ * Resolve the app's dev hostname and rename the printed/opened URL once the
299
+ * server is listening. Returns the hostname so the discovery record can
300
+ * describe the same URL (`primaryServerUrl`).
301
+ *
302
+ * Vite assigns `resolvedUrls` in a `listening` listener it *prepends* in
303
+ * `listen()`, after every `configureServer` hook has run, so this listener
304
+ * always sees them; `printUrls()` and `openBrowser()` run after `listen()`
305
+ * resolves. Middleware mode has no `httpServer` and prints nothing.
306
+ */
307
+ export function applyDevHostname(
308
+ server: DevHostnameServer,
309
+ appDir: string,
310
+ override: string | false | undefined
311
+ ): string {
312
+ const hostname = effectiveDevHostname(
313
+ resolveDevHostname(appDir, override),
314
+ server.config.server?.https
315
+ );
316
+ if (server.httpServer && hostname !== LOCALHOST) {
317
+ server.httpServer.on('listening', () => {
318
+ if (server.resolvedUrls) server.resolvedUrls = withDevHostname(server.resolvedUrls, hostname);
319
+ });
320
+ }
321
+ return hostname;
322
+ }
@@ -12,7 +12,13 @@
12
12
  * Design docs: 18-build-system.md §"Dev Server", 02-rendering-pipeline.md
13
13
  */
14
14
 
15
- import { loadConfigFromFile, type Plugin, type ViteDevServer, type DevEnvironment } from 'vite';
15
+ import {
16
+ loadConfigFromFile,
17
+ normalizePath,
18
+ type Plugin,
19
+ type ViteDevServer,
20
+ type DevEnvironment,
21
+ } from 'vite';
16
22
  import type { IncomingMessage, ServerResponse } from 'node:http';
17
23
  import type { TLSSocket } from 'node:tls';
18
24
  import { existsSync, realpathSync, statSync } from 'node:fs';
@@ -32,7 +38,8 @@ import {
32
38
  type DevHooks,
33
39
  } from '../dev-tools/dev-page-shell.ts';
34
40
  import { addVirtualModuleContext } from '../config-validation.ts';
35
- import { registerDevDiscovery } from './dev-discovery.ts';
41
+ import { devRecordRoot, registerDevDiscovery } from './dev-discovery.ts';
42
+ import { advertisedUrls, applyDevHostname } from './dev-hostname.ts';
36
43
  import {
37
44
  createGraphEndpointMiddleware,
38
45
  makeGraphUpdateChannel,
@@ -40,9 +47,9 @@ import {
40
47
  } from './graph-endpoint.ts';
41
48
  import { compressResponse } from '../server/compress.ts';
42
49
  import { isMetadataRouteServePath } from '../server/metadata-routes.ts';
43
- import { canonicalize } from '../server/canonicalize.ts';
44
- import { PREBUILT_DEV_CLEAR_EVENT } from '../server/prebuilt/dev-store.ts';
45
- import { clearDevStoreOnWatcherEvents } from './dev-store-clear.ts';
50
+ import { canonicalize, requestTargetUrl } from '../server/canonicalize.ts';
51
+ import { PREBUILT_DEV_CLEAR_EVENT, type DevStoreClear } from '../server/prebuilt/dev-store.ts';
52
+ import { clearDevStoreOnWatcherEvents, componentsChangedBy } from './dev-store-clear.ts';
46
53
  import { matchUrlParts } from '../server/tree-match.ts';
47
54
  import type { RouteTree } from '../routing/types.ts';
48
55
 
@@ -198,6 +205,20 @@ export function timberDevServer(ctx: PluginContext): Plugin {
198
205
  // as Vite's '{ type: "error" }' payload to trigger the overlay.
199
206
  listenForClientErrors(server, ctx.root);
200
207
 
208
+ // Before any of Vite's middlewares: an absolute-form or asterisk-form
209
+ // target becomes the origin-form path the pipeline will see, so Vite's
210
+ // transform/static middlewares and the checks in the timber
211
+ // middleware agree with it — `GET http://host/@vite/client` is Vite's,
212
+ // not a 404 from the app (TIM-1600). A target that names no URL is
213
+ // left for toWebRequest to answer with 400.
214
+ server.middlewares.use((req, _res, next) => {
215
+ if (req.url && !req.url.startsWith('/')) {
216
+ const url = requestTargetUrl('http://localhost', req.url);
217
+ if (url) req.url = url.pathname + url.search;
218
+ }
219
+ next();
220
+ });
221
+
201
222
  // GET /__timber/graph — module-environment classification from the
202
223
  // live env graphs, plus the timber:graph-update HMR push channel.
203
224
  // Registered before the timber middleware so /__timber/* requests
@@ -205,18 +226,48 @@ export function timberDevServer(ctx: PluginContext): Plugin {
205
226
  // plugin is apply: 'serve'). See design/47 §"Dev-server endpoint".
206
227
  server.middlewares.use(createGraphEndpointMiddleware(server, ctx));
207
228
 
229
+ // Canonicalize watcher/hook paths into the module graphs' path
230
+ // space: under the default preserveSymlinks:false the graphs
231
+ // carry realpaths while watcher events can carry symlink paths
232
+ // — unkeyed by one canonical form, a pending entry would never
233
+ // match its own transform. Deleted files realpath their parent
234
+ // directory instead; virtual ids pass through untouched.
235
+ const toGraphPath = (file: string): string => {
236
+ // Optional-chained: mock servers in unit tests carry a bare
237
+ // config object without resolve options.
238
+ if (server.config?.resolve?.preserveSymlinks || file.includes('virtual:')) return file;
239
+ try {
240
+ return realpathSync(file);
241
+ } catch {
242
+ try {
243
+ return join(realpathSync(dirname(file)), basename(file));
244
+ } catch {
245
+ return file;
246
+ }
247
+ }
248
+ };
249
+
208
250
  // Every watcher event clears the RSC environment's cache.component dev
209
251
  // store (TIM-1588) — source files, and files outside the module graph
210
- // that a component reads with fs. A raw listener, not hotUpdate: it
211
- // runs in the same synchronous dispatch as every other watcher
212
- // listener (timber-routing's reloads included), before Vite's own
213
- // handling sends any HMR update. A browser that a reload or update
252
+ // that a component reads with fs. A save of a module clears only the
253
+ // components it could have changed (TIM-1599). A raw listener, not
254
+ // hotUpdate: it runs in the same synchronous dispatch as every other
255
+ // watcher listener (timber-routing's reloads included), before Vite's
256
+ // own handling sends any HMR update. A browser that a reload or update
214
257
  // makes refetch can only reach the server after the clear has gone
215
258
  // out. A trailing clear covers the saves the watcher drops
216
259
  // (dev-store-clear.ts).
217
- const rscHot = server.environments.rsc?.hot;
218
- clearDevStoreOnWatcherEvents(server.watcher, () => {
219
- rscHot?.send({ type: 'custom', event: PREBUILT_DEV_CLEAR_EVENT });
260
+ const rsc = server.environments.rsc;
261
+ clearDevStoreOnWatcherEvents(server.watcher, (changed) => {
262
+ if (!rsc) return;
263
+ const componentIds = componentsChangedBy(
264
+ changed,
265
+ rsc.moduleGraph,
266
+ ctx.devPrebuiltComponentIds ?? new Map(),
267
+ (path) => normalizePath(toGraphPath(path))
268
+ );
269
+ const data: DevStoreClear = componentIds === null ? {} : { componentIds };
270
+ rsc.hot.send({ type: 'custom', event: PREBUILT_DEV_CLEAR_EVENT, data });
220
271
  });
221
272
  graphChannel = makeGraphUpdateChannel(
222
273
  ctx,
@@ -238,35 +289,26 @@ export function timberDevServer(ctx: PluginContext): Plugin {
238
289
  }
239
290
  return graph.getModuleById(file)?.transformResult != null;
240
291
  },
241
- // Canonicalize watcher/hook paths into the module graphs' path
242
- // space: under the default preserveSymlinks:false the graphs
243
- // carry realpaths while watcher events can carry symlink paths
244
- // — unkeyed by one canonical form, a pending entry would never
245
- // match its own transform. Deleted files realpath their parent
246
- // directory instead; virtual ids pass through untouched.
247
- (file) => {
248
- // Optional-chained: mock servers in unit tests carry a bare
249
- // config object without resolve options.
250
- if (server.config?.resolve?.preserveSymlinks || file.includes('virtual:')) return file;
251
- try {
252
- return realpathSync(file);
253
- } catch {
254
- try {
255
- return join(realpathSync(dirname(file)), basename(file));
256
- } catch {
257
- return file;
258
- }
259
- }
260
- }
292
+ toGraphPath
261
293
  );
262
294
 
263
295
  // Pre-hook — registers middleware before Vite's internals
264
296
  server.middlewares.use(createTimberMiddleware(server, ctx));
265
297
 
298
+ // Print and open <name>.localhost:<port> instead of localhost:<port>, so
299
+ // each app gets its own cookie jar. See design/21 §Dev Hostnames.
300
+ const appDir = devRecordRoot(ctx.root, server.config.configFile);
301
+ const hostname = applyDevHostname(server, appDir, ctx.config.dev?.hostname);
302
+
266
303
  // Write this server's .timber/dev/<pid>-<port>-<token>.json record once
267
- // the server is listening so the graph CLI / VS Code extension can
268
- // discover it. See design/47-module-environment-tooling.md §5.
269
- registerDevDiscovery(server.httpServer, ctx.root, server.config);
304
+ // the server is listening so `timber dev status`, the graph CLI and the
305
+ // VS Code extension can discover it. See design/21 §Discovery Records.
306
+ registerDevDiscovery(
307
+ server.httpServer,
308
+ ctx.root,
309
+ () => advertisedUrls(server.resolvedUrls, hostname, server.config.server),
310
+ server.config
311
+ );
270
312
 
271
313
  // Close the holding server and await the port release so Vite's
272
314
  // port probe and bind see a free port. configureServer is awaited
@@ -403,6 +445,13 @@ function createTimberMiddleware(server: ViteDevServer, ctx: PluginContext) {
403
445
  try {
404
446
  // Convert Node IncomingMessage → Web Request
405
447
  const webRequest = toWebRequest(req);
448
+ // A malformed Host or request target is the client's error: a 400,
449
+ // not a 500 and an overlay for a bug the app doesn't have (TIM-1600).
450
+ if (!webRequest) {
451
+ res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' });
452
+ res.end('Bad Request');
453
+ return;
454
+ }
406
455
 
407
456
  // Check for a platform-specific request wrapper (e.g., Cloudflare
408
457
  // dev bindings). The cloudflareDevBindings() plugin stores a wrapper
@@ -518,15 +567,25 @@ function addTimberContext(error: Error): void {
518
567
  * consulted: dev connections are direct, so the header would be
519
568
  * attacker-controlled. (TIM-1067, B32)
520
569
  *
570
+ * Returns null for a request that names no URL — a Host that is not a bare
571
+ * host[:port], or a request target that does not parse — which the caller
572
+ * answers with 400. (TIM-1600)
573
+ *
521
574
  * Exported for tests.
522
575
  */
523
- export function toWebRequest(nodeReq: IncomingMessage): Request {
576
+ export function toWebRequest(nodeReq: IncomingMessage): Request | null {
524
577
  const protocol = (nodeReq.socket as TLSSocket | undefined)?.encrypted ? 'https' : 'http';
525
578
  // Under HTTP/2 there is no Host header — the authority lives in the
526
579
  // `:authority` pseudo-header.
527
580
  const host =
528
581
  nodeReq.headers.host ?? (nodeReq.headers[':authority'] as string | undefined) ?? 'localhost';
529
- const url = `${protocol}://${host}${nodeReq.url}`;
582
+ // The Host is an authority, nothing more. Pasted into the URL, one with a
583
+ // path or query moves the request target: `Host: localhost:5173/x?` and
584
+ // target `/admin` would route `/x` with search `?/admin`. A backslash is a
585
+ // path separator to the URL parser, and `@` would make the host userinfo.
586
+ const origin = /[/?#@\\]/.test(host) ? null : URL.parse(`${protocol}://${host}`)?.origin;
587
+ const url = origin ? requestTargetUrl(origin, nodeReq.url || '/') : null;
588
+ if (!url) return null;
530
589
 
531
590
  const headers = new Headers();
532
591
  for (const [key, value] of Object.entries(nodeReq.headers)) {
@@ -2,6 +2,32 @@
2
2
  * Clear the cache.component dev store on every dev-server watcher event
3
3
  * (TIM-1588, server/prebuilt/dev-store.ts) — and once more shortly after.
4
4
  *
5
+ * A clear is scoped when the RSC module graph can say what a save changed
6
+ * (TIM-1599). A `change` to a file the graph knows as a module can only have
7
+ * changed the output of the modules that import it, transitively, so only
8
+ * the components declared in those modules (and in the file itself) are
9
+ * dropped. Element props need no tracking: non-slot element props make a
10
+ * render unkeyable, and slot content is composed live (design/45 §Cache Key,
11
+ * §Slot Components). Nested cache.component children are baked flat into
12
+ * their parent, whose module imports them, so the walk reaches the parent.
13
+ *
14
+ * The graph also holds file-only entries: files a plugin declared with
15
+ * `addWatchFile`. Tailwind's plugin declares every file its scanner finds,
16
+ * markdown and JSON included, as a dependency of the stylesheet. A file-only
17
+ * entry says what watches the file, never what reads it with fs, so a file
18
+ * with no module node clears everything. When the walk meets one on its way
19
+ * up (a module Tailwind also scans), it goes through it to the stylesheet's
20
+ * importers, which costs extra re-renders of components declared up that
21
+ * chain and never a stale one.
22
+ *
23
+ * Everything else clears every component: a file the graph does not know as
24
+ * a module (markdown or JSON read with fs), and an add or a delete (a glob
25
+ * or a route scan may pick it up). The decision is graph membership, never
26
+ * the file's extension. Not covered: a module loaded by a variable dynamic
27
+ * `import()` that Vite cannot analyze has no importer edge, and a component
28
+ * that reads a project module with fs is not that module's importer. A hard
29
+ * reload covers both.
30
+ *
5
31
  * Vite's watcher (chokidar) throttles `change`: once it emits one for a
6
32
  * path, it DROPS every further `change` for that path for 50ms, and never
7
33
  * emits a trailing event for them. So a save is invisible when it lands
@@ -13,8 +39,12 @@
13
39
  * fs was read again on every request.
14
40
  *
15
41
  * The trailing clear lands after that window closes, so it follows any
16
- * write whose event was dropped. A render that started before it cannot
17
- * store (the clear records an invalidation of everything), and a render
42
+ * write whose event was dropped. A dropped event is always for a path the
43
+ * burst already reported, so the trailing clear covers every path seen in
44
+ * the burst, and resolves them against the graph again when it fires: a
45
+ * request between the saves may have re-transformed a module and given its
46
+ * call sites new IDs. A render of a covered component that started before
47
+ * it cannot store (the clear records an invalidation of it), and a render
18
48
  * after it reads the file as written. Debounced, so a burst of saves gets
19
49
  * one trailing clear, after the last of them. The cost is at most one
20
50
  * extra re-render per save, in dev only.
@@ -32,16 +62,84 @@ const TRAILING_CLEAR_DELAY_MS = WATCHER_CHANGE_THROTTLE_MS * 2;
32
62
 
33
63
  /** The part of Vite's `FSWatcher` this needs. */
34
64
  interface WatcherEvents {
35
- on(event: 'all', listener: () => void): unknown;
65
+ on(event: 'all', listener: (event: string, path: string) => void): unknown;
36
66
  }
37
67
 
38
- export function clearDevStoreOnWatcherEvents(watcher: WatcherEvents, clear: () => void): void {
68
+ /**
69
+ * What a clear covers: the paths changed in place, or null for anything
70
+ * else (an add, a delete, a directory event), which clears everything.
71
+ */
72
+ export type ChangedPaths = ReadonlySet<string> | null;
73
+
74
+ export function clearDevStoreOnWatcherEvents(
75
+ watcher: WatcherEvents,
76
+ clear: (changed: ChangedPaths) => void
77
+ ): void {
39
78
  let trailing: ReturnType<typeof setTimeout> | undefined;
40
- watcher.on('all', () => {
41
- clear();
79
+ // Every path the burst reported, or null once anything cleared everything.
80
+ let burst: Set<string> | null = new Set();
81
+ watcher.on('all', (event, path) => {
82
+ const changed = event === 'change' ? new Set([path]) : null;
83
+ clear(changed);
84
+ if (changed === null) burst = null;
85
+ else burst?.add(path);
42
86
  clearTimeout(trailing);
43
- trailing = setTimeout(clear, TRAILING_CLEAR_DELAY_MS);
87
+ trailing = setTimeout(() => {
88
+ const covered = burst;
89
+ burst = new Set();
90
+ clear(covered);
91
+ }, TRAILING_CLEAR_DELAY_MS);
44
92
  // Never the reason the dev process stays alive.
45
93
  trailing.unref?.();
46
94
  });
47
95
  }
96
+
97
+ /** The part of Vite's `EnvironmentModuleNode` the walk reads. */
98
+ export interface GraphModule {
99
+ /** Null for a file-only entry (`addWatchFile`), which declares nothing. */
100
+ id: string | null;
101
+ importers: Set<GraphModule>;
102
+ }
103
+
104
+ /** The part of Vite's `EnvironmentModuleGraph` the walk reads. */
105
+ export interface ModuleGraphView {
106
+ getModulesByFile(file: string): Set<GraphModule> | undefined;
107
+ }
108
+
109
+ /**
110
+ * The cache.component IDs whose output the changed paths could have
111
+ * changed: those declared in each changed module and its transitive
112
+ * importers. Null means every component — a path the graph does not know.
113
+ *
114
+ * `componentIds` maps a module ID to the IDs its last transform declared
115
+ * (`PluginContext.devPrebuiltComponentIds`). `toGraphPath` puts a watcher
116
+ * path in the graph's path space (symlinks resolved, `/` separators).
117
+ */
118
+ export function componentsChangedBy(
119
+ changed: ChangedPaths,
120
+ graph: ModuleGraphView,
121
+ componentIds: ReadonlyMap<string, readonly string[]>,
122
+ toGraphPath: (path: string) => string
123
+ ): string[] | null {
124
+ if (changed === null) return null;
125
+ const affected = new Set<string>();
126
+ const visited = new Set<GraphModule>();
127
+ const pending: GraphModule[] = [];
128
+ for (const path of changed) {
129
+ const nodes = [...(graph.getModulesByFile(toGraphPath(path)) ?? [])];
130
+ // Known as a module, or not at all: a file that only a plugin watches
131
+ // may also be read with fs, by any component.
132
+ if (!nodes.some((node) => node.id !== null)) return null;
133
+ pending.push(...nodes);
134
+ }
135
+ while (pending.length > 0) {
136
+ const module = pending.pop()!;
137
+ if (visited.has(module)) continue;
138
+ visited.add(module);
139
+ if (module.id !== null) {
140
+ for (const id of componentIds.get(module.id) ?? []) affected.add(id);
141
+ }
142
+ pending.push(...module.importers);
143
+ }
144
+ return [...affected];
145
+ }