@timber-js/app 0.2.0-alpha.235 → 0.2.0-alpha.237

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 (300) hide show
  1. package/dist/_chunks/{actions-CYjRMpZI.js → actions-Top9GftB.js} +3 -3
  2. package/dist/_chunks/{actions-CYjRMpZI.js.map → actions-Top9GftB.js.map} +1 -1
  3. package/dist/_chunks/{cache-api-BZJNt01a.js → cache-api-Bo8c7XVF.js} +6 -6
  4. package/dist/_chunks/{cache-api-BZJNt01a.js.map → cache-api-Bo8c7XVF.js.map} +1 -1
  5. package/dist/_chunks/{chains-D-RRc7CM.js → chains-BsGKkMTK.js} +2 -2
  6. package/dist/_chunks/{chains-D-RRc7CM.js.map → chains-BsGKkMTK.js.map} +1 -1
  7. package/dist/_chunks/chains-DHmoKxkO.js +1 -0
  8. package/dist/_chunks/{classify-_W0RWa5w.js → classify-cmE0Gins.js} +2 -2
  9. package/dist/_chunks/{classify-_W0RWa5w.js.map → classify-cmE0Gins.js.map} +1 -1
  10. package/dist/_chunks/{cli-check-Dl3yo3Zv.js → cli-check-BwiahbTC.js} +3 -3
  11. package/dist/_chunks/{cli-check-Dl3yo3Zv.js.map → cli-check-BwiahbTC.js.map} +1 -1
  12. package/dist/_chunks/{cli-schema-sync-CyrOHbAo.js → cli-schema-sync-B2ldclRO.js} +2 -2
  13. package/dist/_chunks/{cli-schema-sync-CyrOHbAo.js.map → cli-schema-sync-B2ldclRO.js.map} +1 -1
  14. package/dist/_chunks/{cli-schema-sync-CTWiBMZZ.js → cli-schema-sync-Brw7kTmm.js} +1 -1
  15. package/dist/_chunks/{client-dep-entries-C9hv-3k9.js → client-dep-entries-C1nMlLKV.js} +2 -2
  16. package/dist/_chunks/{client-dep-entries-C9hv-3k9.js.map → client-dep-entries-C1nMlLKV.js.map} +1 -1
  17. package/dist/_chunks/{cloudflare-_2fhxQE8.js → cloudflare-Dk5Hqo-O.js} +3 -3
  18. package/dist/_chunks/{cloudflare-_2fhxQE8.js.map → cloudflare-Dk5Hqo-O.js.map} +1 -1
  19. package/dist/_chunks/{convention-lint-D54k6uUM.js → convention-lint-CLpuzY5h.js} +3 -3
  20. package/dist/_chunks/{convention-lint-D54k6uUM.js.map → convention-lint-CLpuzY5h.js.map} +1 -1
  21. package/dist/_chunks/dev-server-BGGGhHXx.js +1 -0
  22. package/dist/_chunks/{dev-server-cmWVDgTf.js → dev-server-lrdpD7Ws.js} +121 -5
  23. package/dist/_chunks/dev-server-lrdpD7Ws.js.map +1 -0
  24. package/dist/_chunks/{dev-span-_NzMX-au.js → dev-span-RsVeYYc_.js} +5 -2
  25. package/dist/_chunks/dev-span-RsVeYYc_.js.map +1 -0
  26. package/dist/_chunks/{error-boundary-Cf1m-Ywk.js → error-boundary-Bh-egWUI.js} +6 -6
  27. package/dist/_chunks/{error-boundary-Cf1m-Ywk.js.map → error-boundary-Bh-egWUI.js.map} +1 -1
  28. package/dist/_chunks/{flight-source-node-BGanuoSS.js → flight-source-node-BsrlUjMO.js} +7 -3
  29. package/dist/_chunks/flight-source-node-BsrlUjMO.js.map +1 -0
  30. package/dist/_chunks/{href-BtspoNc9.js → href-8l5VD23D.js} +2 -2
  31. package/dist/_chunks/{href-BtspoNc9.js.map → href-8l5VD23D.js.map} +1 -1
  32. package/dist/_chunks/{json-lossy-check-BXM45k8p.js → json-lossy-check-D47R9Fp5.js} +2 -2
  33. package/dist/_chunks/{json-lossy-check-BXM45k8p.js.map → json-lossy-check-D47R9Fp5.js.map} +1 -1
  34. package/dist/_chunks/{live-graph-C7-yA8W9.js → live-graph-ChuFfmLi.js} +4 -4
  35. package/dist/_chunks/{live-graph-C7-yA8W9.js.map → live-graph-ChuFfmLi.js.map} +1 -1
  36. package/dist/_chunks/{logger-YtMSKfft.js → logger-DDLtp5e-.js} +16 -1
  37. package/dist/_chunks/logger-DDLtp5e-.js.map +1 -0
  38. package/dist/_chunks/navigation-root-Cvb7P1ud.js.map +1 -1
  39. package/dist/_chunks/{node-response-D3hXWb8y.js → node-response-omewa8e6.js} +21 -4
  40. package/dist/_chunks/node-response-omewa8e6.js.map +1 -0
  41. package/dist/_chunks/{poison-scan-CRSP06Es.js → poison-scan-CJ9QfJWb.js} +2 -2
  42. package/dist/_chunks/{poison-scan-CRSP06Es.js.map → poison-scan-CJ9QfJWb.js.map} +1 -1
  43. package/dist/_chunks/render-timeout-MrrqD1wd.js.map +1 -1
  44. package/dist/_chunks/{scanner-BNQ4qnLX.js → scanner-CrB_h6FA.js} +5 -5
  45. package/dist/_chunks/{scanner-BNQ4qnLX.js.map → scanner-CrB_h6FA.js.map} +1 -1
  46. package/dist/_chunks/{sizeof-Cmx6Fs-Y.js → sizeof-DVhEVN_y.js} +2 -2
  47. package/dist/_chunks/{sizeof-Cmx6Fs-Y.js.map → sizeof-DVhEVN_y.js.map} +1 -1
  48. package/dist/_chunks/{walkers-DFC9KsBL.js → walkers-BUvpsb2Q.js} +3 -3
  49. package/dist/_chunks/{walkers-DFC9KsBL.js.map → walkers-BUvpsb2Q.js.map} +1 -1
  50. package/dist/adapters/cloudflare-dev.js +1 -1
  51. package/dist/adapters/cloudflare-kv-cache.js +2 -2
  52. package/dist/adapters/cloudflare.js +1 -1
  53. package/dist/adapters/nitro.js +1 -1
  54. package/dist/analyze/crawl-entry.js +3 -3
  55. package/dist/analyze/graph-command.js +3 -3
  56. package/dist/cache/index.js +2 -2
  57. package/dist/cache/stores/memory.js +1 -1
  58. package/dist/cli.js +3 -3
  59. package/dist/client/dev-pill/index.d.ts +2 -1
  60. package/dist/client/dev-pill/index.d.ts.map +1 -1
  61. package/dist/client/dev-pill/view.d.ts.map +1 -1
  62. package/dist/client/error-boundary.js +1 -1
  63. package/dist/client/index.js +4 -4
  64. package/dist/client/internal.js +3 -3
  65. package/dist/cookies/index.js +1 -1
  66. package/dist/dev-tools/await-span.d.ts +7 -0
  67. package/dist/dev-tools/await-span.d.ts.map +1 -1
  68. package/dist/dev-tools/instrumentation.d.ts.map +1 -1
  69. package/dist/dev-tools/logger.d.ts +8 -2
  70. package/dist/dev-tools/logger.d.ts.map +1 -1
  71. package/dist/dev-tools/span-sink.d.ts +9 -1
  72. package/dist/dev-tools/span-sink.d.ts.map +1 -1
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +73 -31
  75. package/dist/index.js.map +1 -1
  76. package/dist/native/rsc/_react/chunks/{react-server-dom-webpack-server.node.development-hQ_odxIB.js → react-server-dom-webpack-server.node.development-CAttMzVD.js} +2 -2
  77. package/dist/native/rsc/_react/flight-client.js +2 -2
  78. package/dist/native/rsc/_react/flight-server.js +1 -1
  79. package/dist/native/rsc/_react/flight-static.js +1 -1
  80. package/dist/native/rsc/adapters/cloudflare-kv-cache.js +1 -1
  81. package/dist/native/rsc/adapters/cloudflare.js +2 -2
  82. package/dist/native/rsc/cache/cache-api.js +3 -3
  83. package/dist/native/rsc/cache/index.js +3 -3
  84. package/dist/native/rsc/cache/timber-cache.js +2 -2
  85. package/dist/native/rsc/cdn/index.js +1 -1
  86. package/dist/native/rsc/client/use-cookie.js +1 -1
  87. package/dist/native/rsc/dev-tools/404-page.js +1 -1
  88. package/dist/native/rsc/dev-tools/await-span.js +5 -2
  89. package/dist/native/rsc/dev-tools/await-span.js.map +1 -1
  90. package/dist/native/rsc/dev-tools/error-page.js +2 -2
  91. package/dist/native/rsc/dev-tools/instrumentation.js +38 -3
  92. package/dist/native/rsc/dev-tools/instrumentation.js.map +1 -1
  93. package/dist/native/rsc/dev-tools/logger.js +123 -80
  94. package/dist/native/rsc/dev-tools/logger.js.map +1 -1
  95. package/dist/native/rsc/dev-tools/span-sink.js +1 -0
  96. package/dist/native/rsc/dev-tools/span-sink.js.map +1 -1
  97. package/dist/native/rsc/dev-tools/terminal.js +1 -1
  98. package/dist/native/rsc/manifest.json +1 -0
  99. package/dist/native/rsc/params/index.js +1 -1
  100. package/dist/native/rsc/routing/collision-probe.js +1 -1
  101. package/dist/native/rsc/routing/interception.js +1 -1
  102. package/dist/native/rsc/search-params/define.js +2 -2
  103. package/dist/native/rsc/server/abort-scope.js +6 -2
  104. package/dist/native/rsc/server/abort-scope.js.map +1 -1
  105. package/dist/native/rsc/server/access-gate.js +1 -1
  106. package/dist/native/rsc/server/action-client.js +2 -2
  107. package/dist/native/rsc/server/action-handler.js +8 -8
  108. package/dist/native/rsc/server/actions.js +3 -3
  109. package/dist/native/rsc/server/children-interception.js +1 -1
  110. package/dist/native/rsc/server/deny-boundary.js +1 -1
  111. package/dist/native/rsc/server/deny-renderer.js +10 -10
  112. package/dist/native/rsc/server/fallback-error.js +1 -1
  113. package/dist/native/rsc/server/flight-injector-core.js +2 -2
  114. package/dist/native/rsc/server/flight-source-node.js +8 -4
  115. package/dist/native/rsc/server/flight-source-node.js.map +1 -1
  116. package/dist/native/rsc/server/index.js +4 -4
  117. package/dist/native/rsc/server/interception-gates.js +2 -2
  118. package/dist/native/rsc/server/internal.js +15 -15
  119. package/dist/native/rsc/server/logger.js +2 -2
  120. package/dist/native/rsc/server/metadata-route-links.js +1 -1
  121. package/dist/native/rsc/server/node-body-response.js +1 -1
  122. package/dist/native/rsc/server/param-coercion.js +1 -1
  123. package/dist/native/rsc/server/pipeline-helpers.js +11 -11
  124. package/dist/native/rsc/server/pipeline-helpers.js.map +1 -1
  125. package/dist/native/rsc/server/pipeline-interception.js +4 -4
  126. package/dist/native/rsc/server/pipeline-metadata-route.js +11 -11
  127. package/dist/native/rsc/server/pipeline-metadata-route.js.map +1 -1
  128. package/dist/native/rsc/server/pipeline-outcome.js +4 -4
  129. package/dist/native/rsc/server/pipeline-phases.js +11 -11
  130. package/dist/native/rsc/server/pipeline.js +10 -10
  131. package/dist/native/rsc/server/prebuilt/capture-render.js +1 -1
  132. package/dist/native/rsc/server/prebuilt/dev-store.js +1 -1
  133. package/dist/native/rsc/server/prebuilt/overlay.js +3 -3
  134. package/dist/native/rsc/server/prebuilt-builder.js +8 -8
  135. package/dist/native/rsc/server/prebuilt-runtime.js +15 -15
  136. package/dist/native/rsc/server/primitives.js +2 -2
  137. package/dist/native/rsc/server/publish-params.js +1 -1
  138. package/dist/native/rsc/server/render-timeout.js.map +1 -1
  139. package/dist/native/rsc/server/request-context.js +1 -1
  140. package/dist/native/rsc/server/route-element-builder.js +7 -7
  141. package/dist/native/rsc/server/route-element-helpers.js +1 -1
  142. package/dist/native/rsc/server/route-handler.js +1 -1
  143. package/dist/native/rsc/server/rsc-entry/action-dispatcher.js +1 -1
  144. package/dist/native/rsc/server/rsc-entry/action-middleware-runner.js +1 -1
  145. package/dist/native/rsc/server/rsc-entry/api-handler.js +1 -1
  146. package/dist/native/rsc/server/rsc-entry/deny-fallback.js +6 -6
  147. package/dist/native/rsc/server/rsc-entry/error-renderer.js +7 -7
  148. package/dist/native/rsc/server/rsc-entry/helpers.js +1 -1
  149. package/dist/native/rsc/server/rsc-entry/render-route.js +4 -4
  150. package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +7 -7
  151. package/dist/native/rsc/server/rsc-entry/rsc-payload.js +3 -3
  152. package/dist/native/rsc/server/rsc-entry/rsc-stream.js +6 -6
  153. package/dist/native/rsc/server/rsc-entry/ssr-renderer.js +10 -10
  154. package/dist/native/rsc/server/rsc-error-envelope.js +1 -1
  155. package/dist/native/rsc/server/safe-load.js +14 -2
  156. package/dist/native/rsc/server/safe-load.js.map +1 -1
  157. package/dist/native/rsc/server/sitemap-handler.js +1 -1
  158. package/dist/native/rsc/server/skippable-prefix.js +2 -2
  159. package/dist/native/rsc/server/slot-interception.js +1 -1
  160. package/dist/native/rsc/server/slot-resolver.js +11 -11
  161. package/dist/native/rsc/server/static-generator.js +2 -2
  162. package/dist/native/rsc/server/traced-access.js +1 -1
  163. package/dist/native/rsc/server/tracing.js +10 -0
  164. package/dist/native/rsc/server/tracing.js.map +1 -1
  165. package/dist/native/rsc/shared/dev-span.js +8 -2
  166. package/dist/native/rsc/shared/dev-span.js.map +1 -1
  167. package/dist/native/rsc/shared/href.js +1 -1
  168. package/dist/native/rsc/shared/span-waterfall.js +90 -0
  169. package/dist/native/rsc/shared/span-waterfall.js.map +1 -0
  170. package/dist/native/ssr/adapters/cloudflare-kv-cache.js +1 -1
  171. package/dist/native/ssr/adapters/cloudflare.js +2 -2
  172. package/dist/native/ssr/cache/cache-api.js +3 -3
  173. package/dist/native/ssr/cache/guarded-read.js +1 -1
  174. package/dist/native/ssr/cache/index.js +3 -3
  175. package/dist/native/ssr/cache/timber-cache.js +3 -3
  176. package/dist/native/ssr/cdn/index.js +1 -1
  177. package/dist/native/ssr/client/error-boundary.js +1 -1
  178. package/dist/native/ssr/client/index.js +5 -5
  179. package/dist/native/ssr/client/link.js +5 -5
  180. package/dist/native/ssr/client/navigation-commit.js +2 -2
  181. package/dist/native/ssr/client/nuqs-adapter.js +2 -2
  182. package/dist/native/ssr/client/params-context.js +1 -1
  183. package/dist/native/ssr/client/router-skew.js +1 -1
  184. package/dist/native/ssr/client/rsc-fetch.js +2 -2
  185. package/dist/native/ssr/client/use-pending-navigation.js +1 -1
  186. package/dist/native/ssr/client/use-search-params.js +2 -2
  187. package/dist/native/ssr/client/use-segment-params.js +1 -1
  188. package/dist/native/ssr/client/use-selected-layout-segment.js +1 -1
  189. package/dist/native/ssr/dev-tools/await-span.js +5 -2
  190. package/dist/native/ssr/dev-tools/await-span.js.map +1 -1
  191. package/dist/native/ssr/dev-tools/instrumentation.js +38 -3
  192. package/dist/native/ssr/dev-tools/instrumentation.js.map +1 -1
  193. package/dist/native/ssr/dev-tools/logger.js +123 -80
  194. package/dist/native/ssr/dev-tools/logger.js.map +1 -1
  195. package/dist/native/ssr/dev-tools/span-sink.js +1 -0
  196. package/dist/native/ssr/dev-tools/span-sink.js.map +1 -1
  197. package/dist/native/ssr/manifest.json +1 -0
  198. package/dist/native/ssr/params/index.js +1 -1
  199. package/dist/native/ssr/search-params/define.js +2 -2
  200. package/dist/native/ssr/server/abort-scope.js +6 -2
  201. package/dist/native/ssr/server/abort-scope.js.map +1 -1
  202. package/dist/native/ssr/server/access-gate.js +1 -1
  203. package/dist/native/ssr/server/action-client.js +2 -2
  204. package/dist/native/ssr/server/actions.js +3 -3
  205. package/dist/native/ssr/server/deny-boundary.js +2 -2
  206. package/dist/native/ssr/server/flight-injector-core.js +1 -1
  207. package/dist/native/ssr/server/flight-source-node.js +8 -4
  208. package/dist/native/ssr/server/flight-source-node.js.map +1 -1
  209. package/dist/native/ssr/server/index.js +4 -4
  210. package/dist/native/ssr/server/internal.js +12 -12
  211. package/dist/native/ssr/server/logger.js +2 -2
  212. package/dist/native/ssr/server/node-body-response.js +1 -1
  213. package/dist/native/ssr/server/node-stream-transforms.js +2 -2
  214. package/dist/native/ssr/server/param-coercion.js +3 -3
  215. package/dist/native/ssr/server/pipeline-helpers.js +8 -8
  216. package/dist/native/ssr/server/pipeline-helpers.js.map +1 -1
  217. package/dist/native/ssr/server/pipeline-interception.js +4 -4
  218. package/dist/native/ssr/server/pipeline-metadata-route.js +11 -11
  219. package/dist/native/ssr/server/pipeline-metadata-route.js.map +1 -1
  220. package/dist/native/ssr/server/pipeline-outcome.js +4 -4
  221. package/dist/native/ssr/server/pipeline-phases.js +10 -10
  222. package/dist/native/ssr/server/pipeline.js +10 -10
  223. package/dist/native/ssr/server/prebuilt/capture-render.js +2 -2
  224. package/dist/native/ssr/server/prebuilt/dev-store.js +1 -1
  225. package/dist/native/ssr/server/prebuilt/overlay.js +4 -4
  226. package/dist/native/ssr/server/prebuilt-runtime.js +14 -14
  227. package/dist/native/ssr/server/primitives.js +2 -2
  228. package/dist/native/ssr/server/render-timeout.js +3 -4
  229. package/dist/native/ssr/server/render-timeout.js.map +1 -1
  230. package/dist/native/ssr/server/request-context.js +2 -2
  231. package/dist/native/ssr/server/route-handler.js +1 -1
  232. package/dist/native/ssr/server/rsc-error-envelope.js +1 -1
  233. package/dist/native/ssr/server/safe-load.js +10 -1
  234. package/dist/native/ssr/server/safe-load.js.map +1 -1
  235. package/dist/native/ssr/server/ssr-form-state.js +2 -2
  236. package/dist/native/ssr/server/ssr-wrappers.js +1 -1
  237. package/dist/native/ssr/server/traced-access.js +1 -1
  238. package/dist/native/ssr/server/tracing.js +10 -0
  239. package/dist/native/ssr/server/tracing.js.map +1 -1
  240. package/dist/native/ssr/shared/dev-span.js +8 -2
  241. package/dist/native/ssr/shared/dev-span.js.map +1 -1
  242. package/dist/native/ssr/shared/href.js +1 -1
  243. package/dist/native/ssr/shared/span-waterfall.js +90 -0
  244. package/dist/native/ssr/shared/span-waterfall.js.map +1 -0
  245. package/dist/plugins/dev-precompile.d.ts +84 -0
  246. package/dist/plugins/dev-precompile.d.ts.map +1 -0
  247. package/dist/plugins/dev-server.d.ts.map +1 -1
  248. package/dist/plugins/entries.d.ts.map +1 -1
  249. package/dist/plugins/virtual-ids.d.ts +16 -0
  250. package/dist/plugins/virtual-ids.d.ts.map +1 -0
  251. package/dist/routes/index.js +1 -1
  252. package/dist/routing/index.js +3 -3
  253. package/dist/search-params/index.js +2 -2
  254. package/dist/server/abort-scope.d.ts +7 -0
  255. package/dist/server/abort-scope.d.ts.map +1 -1
  256. package/dist/server/flight-source-node.d.ts.map +1 -1
  257. package/dist/server/index.js +2 -2
  258. package/dist/server/internal.js +57 -17
  259. package/dist/server/internal.js.map +1 -1
  260. package/dist/server/render-timeout.d.ts.map +1 -1
  261. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  262. package/dist/server/safe-load.d.ts +22 -0
  263. package/dist/server/safe-load.d.ts.map +1 -1
  264. package/dist/server/tracing.d.ts.map +1 -1
  265. package/dist/shared/dev-span.d.ts +12 -1
  266. package/dist/shared/dev-span.d.ts.map +1 -1
  267. package/dist/shared/span-waterfall.d.ts +88 -0
  268. package/dist/shared/span-waterfall.d.ts.map +1 -0
  269. package/package.json +2 -2
  270. package/src/client/dev-pill/index.ts +5 -2
  271. package/src/client/dev-pill/store.ts +1 -1
  272. package/src/client/dev-pill/view.ts +15 -5
  273. package/src/dev-tools/await-span.ts +10 -0
  274. package/src/dev-tools/instrumentation.ts +44 -6
  275. package/src/dev-tools/logger.ts +230 -155
  276. package/src/dev-tools/span-sink.ts +34 -3
  277. package/src/index.ts +21 -11
  278. package/src/plugins/dev-precompile.ts +168 -0
  279. package/src/plugins/dev-server.ts +16 -3
  280. package/src/plugins/entries.ts +1 -11
  281. package/src/plugins/virtual-ids.ts +15 -0
  282. package/src/server/abort-scope.ts +20 -1
  283. package/src/server/flight-source-node.ts +11 -2
  284. package/src/server/pipeline-helpers.ts +2 -2
  285. package/src/server/pipeline-metadata-route.ts +2 -2
  286. package/src/server/render-timeout.ts +8 -5
  287. package/src/server/rsc-entry/index.ts +5 -0
  288. package/src/server/safe-load.ts +53 -1
  289. package/src/server/tracing.ts +29 -0
  290. package/src/shared/dev-span.ts +17 -2
  291. package/src/{client/dev-pill/waterfall.ts → shared/span-waterfall.ts} +84 -51
  292. package/dist/_chunks/chains-KblEfYzm.js +0 -1
  293. package/dist/_chunks/dev-server-DrYBIg66.js +0 -1
  294. package/dist/_chunks/dev-server-cmWVDgTf.js.map +0 -1
  295. package/dist/_chunks/dev-span-_NzMX-au.js.map +0 -1
  296. package/dist/_chunks/flight-source-node-BGanuoSS.js.map +0 -1
  297. package/dist/_chunks/logger-YtMSKfft.js.map +0 -1
  298. package/dist/_chunks/node-response-D3hXWb8y.js.map +0 -1
  299. package/dist/client/dev-pill/waterfall.d.ts +0 -64
  300. package/dist/client/dev-pill/waterfall.d.ts.map +0 -1
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Dev pre-compile — transform the server module graphs in the background
3
+ * once the dev server listens, so the first request does not wait on Vite
4
+ * compiling server code module by module.
5
+ *
6
+ * Vite pre-transforms nothing in server environments: the first request's
7
+ * module runner asks for each module as an import reaches it, one after
8
+ * another. On the kitchen-sink that was ~1.2s importing the RSC entry
9
+ * (~270 modules) and ~650ms more importing the SSR entry, which only starts
10
+ * after the RSC render. The crawl here transforms the same graph ahead of
11
+ * the request, without running it.
12
+ *
13
+ * - `env.transformRequest()` only: nothing executes, so the app's
14
+ * instrumentation `register()` and cache handler setup still run at the
15
+ * first request, as before.
16
+ * - Static imports only (`result.deps`), from the entries and the root
17
+ * layout. A route's own page and layouts are dynamic imports of the route
18
+ * manifest; they compile at the request for them.
19
+ * - Errors are swallowed. The request that loads the module hits the same
20
+ * error and reports it as it always has; Vite's `warmupRequest` was
21
+ * rejected because it logs each error a second time.
22
+ *
23
+ * - It stops when the HTTP server closes, and after
24
+ * {@link PRECOMPILE_DEADLINE_MS}. Vite's `close()` waits for every
25
+ * transform in flight, and server environments do not refuse new ones
26
+ * while closing, so a crawl that kept going would hold a restart for the
27
+ * rest of the graph.
28
+ *
29
+ * `analyze/crawl.ts` also walks `transformRequest`, for a different job:
30
+ * classifying every module the app can reach, dynamic imports included, in
31
+ * a throwaway middleware-mode server. Following its edges here would
32
+ * compile every route of the app at each start.
33
+ *
34
+ * See design/21-dev-server.md §"Server Pre-compile".
35
+ */
36
+
37
+ import { normalizePath, type DevEnvironment, type ViteDevServer } from 'vite';
38
+ import type { PluginApi } from '@vitejs/plugin-rsc';
39
+
40
+ /** `TIMBER_DEV_PRECOMPILE=0` turns the crawl off (A/B measurement, escape hatch). */
41
+ export const PRECOMPILE_ENV = 'TIMBER_DEV_PRECOMPILE';
42
+
43
+ /**
44
+ * Past this, the crawl starts no new transform. Generous: ~1.2s covers the
45
+ * kitchen-sink. It bounds a crawl stuck behind a slow transform plugin.
46
+ */
47
+ export const PRECOMPILE_DEADLINE_MS = 60_000;
48
+
49
+ /** The roots of each server environment's crawl. */
50
+ export interface PrecompileRoots {
51
+ rsc: string[];
52
+ ssr: string[];
53
+ }
54
+
55
+ /**
56
+ * The id `transformRequest` takes for an entry of `result.deps`, or null for
57
+ * one it must not follow: a bare specifier, which in a server environment is
58
+ * a Node builtin (`node:fs`) or a package Vite externalized, both loaded by
59
+ * Node natively.
60
+ * Import analysis writes a `\0` virtual id as `/@id/__x00__…`, and other
61
+ * non-URL ids as `/@id/…`; the module runner unwraps both the same way.
62
+ */
63
+ export function crawlableId(dep: string): string | null {
64
+ if (dep.startsWith('/@id/__x00__')) return `\0${dep.slice('/@id/__x00__'.length)}`;
65
+ if (dep.startsWith('/@id/')) return dep.slice('/@id/'.length);
66
+ if (dep.startsWith('/')) return dep;
67
+ return null;
68
+ }
69
+
70
+ /**
71
+ * The URL a module importing `file` asks for, after import analysis: root
72
+ * relative inside the Vite root, `/@fs/…` outside it. Vite shares a
73
+ * transform in flight only between requests for the same URL, so a root
74
+ * seeded as a bare path would be transformed twice when a request for it
75
+ * arrives mid-crawl.
76
+ */
77
+ export function fileUrl(file: string, root: string): string {
78
+ const path = normalizePath(file);
79
+ const base = normalizePath(root).replace(/\/?$/, '/');
80
+ return path.startsWith(base)
81
+ ? path.slice(base.length - 1)
82
+ : `/@fs${path.startsWith('/') ? '' : '/'}${path}`;
83
+ }
84
+
85
+ /**
86
+ * Transform `roots` and every module they statically import in `env`.
87
+ * Starts no transform once `shouldStop()` is true. Resolves with the
88
+ * number of modules visited once the graph is done; never rejects.
89
+ */
90
+ export async function crawlServerGraph(
91
+ env: DevEnvironment,
92
+ roots: string[],
93
+ shouldStop: () => boolean = () => false
94
+ ): Promise<number> {
95
+ const seen = new Set<string>();
96
+ const visit = async (id: string): Promise<void> => {
97
+ if (seen.has(id) || shouldStop()) return;
98
+ seen.add(id);
99
+ let deps: string[];
100
+ try {
101
+ deps = (await env.transformRequest(id))?.deps ?? [];
102
+ } catch {
103
+ return;
104
+ }
105
+ await Promise.all(
106
+ deps.map((dep) => {
107
+ const next = crawlableId(dep);
108
+ return next === null ? undefined : visit(next);
109
+ })
110
+ );
111
+ };
112
+ await Promise.all(roots.map(visit));
113
+ return seen.size;
114
+ }
115
+
116
+ /**
117
+ * The SSR environment loads each client component the RSC render
118
+ * references, by the id plugin-rsc registered for it. Read once the RSC
119
+ * crawl is done: plugin-rsc records a client reference when it transforms
120
+ * the `'use client'` module in the RSC environment.
121
+ */
122
+ function clientReferenceIds(server: ViteDevServer): string[] {
123
+ // What plugin-rsc's own `getPluginApi(config)` does. Vite types a plugin's
124
+ // `api` as `any`; the annotation names its shape. Not imported: plugin-rsc
125
+ // is ESM-only and loaded at runtime (`loadPluginRsc`), never statically.
126
+ const api: PluginApi | undefined = server.config.plugins.find(
127
+ (p) => p.name === 'rsc:minimal'
128
+ )?.api;
129
+ const metaMap = api?.manager.clientReferenceMetaMap ?? {};
130
+ return Object.values(metaMap).flatMap((meta) => {
131
+ const id = crawlableId(meta.importId);
132
+ return id === null ? [] : [id];
133
+ });
134
+ }
135
+
136
+ /**
137
+ * Crawl the RSC graph, then the SSR graph with the client references the
138
+ * RSC crawl found. A request that arrives mid-crawl shares the transforms
139
+ * already in flight for the URLs it asks for.
140
+ */
141
+ export async function precompileServerGraphs(
142
+ server: ViteDevServer,
143
+ roots: PrecompileRoots,
144
+ shouldStop: () => boolean
145
+ ): Promise<void> {
146
+ const { rsc, ssr } = server.environments;
147
+ if (rsc) await crawlServerGraph(rsc, roots.rsc, shouldStop);
148
+ if (ssr && !shouldStop()) {
149
+ await crawlServerGraph(ssr, [...roots.ssr, ...clientReferenceIds(server)], shouldStop);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Start the crawl in the background once `server` listens. Middleware mode
155
+ * (no HTTP server of Vite's own) is left alone: the host decides when
156
+ * requests start.
157
+ */
158
+ export function precompileOnListen(server: ViteDevServer, roots: () => PrecompileRoots): void {
159
+ const { httpServer } = server;
160
+ if (process.env[PRECOMPILE_ENV] === '0' || !httpServer) return;
161
+ let closed = false;
162
+ httpServer.once('close', () => (closed = true));
163
+ httpServer.once('listening', () => {
164
+ const deadline = Date.now() + PRECOMPILE_DEADLINE_MS;
165
+ const shouldStop = () => closed || Date.now() > deadline;
166
+ void precompileServerGraphs(server, roots(), shouldStop).catch(() => {});
167
+ });
168
+ }
@@ -39,6 +39,8 @@ import {
39
39
  } from '../dev-tools/dev-page-shell.ts';
40
40
  import { addVirtualModuleContext } from '../config-validation.ts';
41
41
  import { devRecordRoot, registerDevDiscovery } from './dev-discovery.ts';
42
+ import { fileUrl, precompileOnListen } from './dev-precompile.ts';
43
+ import { VIRTUAL_IDS } from './virtual-ids.ts';
42
44
  import { advertisedUrls, applyDevHostname } from './dev-hostname.ts';
43
45
  import {
44
46
  createGraphEndpointMiddleware,
@@ -55,8 +57,6 @@ import type { RouteTree } from '../routing/types.ts';
55
57
 
56
58
  // ─── Constants ────────────────────────────────────────────────────────────
57
59
 
58
- const RSC_ENTRY_ID = 'virtual:timber-rsc-entry';
59
-
60
60
  /**
61
61
  * Exit code used to signal the CLI supervisor that the dev server needs
62
62
  * a full process restart (e.g. timber.config.ts changed). The supervisor
@@ -310,6 +310,19 @@ export function timberDevServer(ctx: PluginContext): Plugin {
310
310
  server.config
311
311
  );
312
312
 
313
+ // Transform the server graphs in the background once listening, so
314
+ // the first request does not compile them one module at a time. See
315
+ // design/21 §Server Pre-compile.
316
+ precompileOnListen(server, () => {
317
+ const rootLayout = ctx.routeTree?.root.layout?.filePath;
318
+ return {
319
+ rsc: rootLayout
320
+ ? [VIRTUAL_IDS.rscEntry, fileUrl(rootLayout, server.config.root)]
321
+ : [VIRTUAL_IDS.rscEntry],
322
+ ssr: [VIRTUAL_IDS.ssrEntry],
323
+ };
324
+ });
325
+
313
326
  // Close the holding server and await the port release so Vite's
314
327
  // port probe and bind see a free port. configureServer is awaited
315
328
  // by Vite during createServer(), before startServer() runs
@@ -407,7 +420,7 @@ function createTimberMiddleware(server: ViteDevServer, ctx: PluginContext) {
407
420
  if (!rscEnv?.runner?.import) {
408
421
  throw new Error('[timber] RSC environment is not runnable');
409
422
  }
410
- const rscModule = await rscEnv.runner.import(RSC_ENTRY_ID);
423
+ const rscModule = await rscEnv.runner.import(VIRTUAL_IDS.rscEntry);
411
424
  handler = rscModule.default as (req: Request) => Promise<Response>;
412
425
 
413
426
  // Wire pipeline errors into the browser error overlay, and plumb the
@@ -17,6 +17,7 @@ import { fileURLToPath } from 'node:url';
17
17
  import { existsSync } from 'node:fs';
18
18
  import type { PluginContext } from '../plugin-context.ts';
19
19
  import { resolveRenderTimeoutMs } from '../server/render-timeout.ts';
20
+ import { VIRTUAL_IDS } from './virtual-ids.ts';
20
21
 
21
22
  const __dirname = dirname(fileURLToPath(import.meta.url));
22
23
 
@@ -27,17 +28,6 @@ export const SRC_DIR = existsSync(resolve(__dirname, '..', 'server', 'rsc-entry'
27
28
  ? resolve(__dirname, '..')
28
29
  : resolve(__dirname, '..', 'src');
29
30
 
30
- // ─── Virtual Module IDs ──────────────────────────────────────────────────
31
-
32
- const VIRTUAL_IDS = {
33
- rscEntry: 'virtual:timber-rsc-entry',
34
- ssrEntry: 'virtual:timber-ssr-entry',
35
- browserEntry: 'virtual:timber-browser-entry',
36
- config: 'virtual:timber-config',
37
- instrumentation: 'virtual:timber-instrumentation',
38
- cacheHandler: 'virtual:timber-cache-handler',
39
- } as const;
40
-
41
31
  /**
42
32
  * Map from virtual module IDs to their resolved file paths.
43
33
  *
@@ -0,0 +1,15 @@
1
+ /**
2
+ * timber's virtual module IDs. A module of its own, with no imports, so any
3
+ * plugin can name an entry without importing `entries.ts`: that module
4
+ * finds `src/` from its own location (`SRC_DIR`), and an import from a
5
+ * plugin the bundler places in another chunk moves it there and breaks the
6
+ * lookup in the published package (TIM-1627).
7
+ */
8
+ export const VIRTUAL_IDS = {
9
+ rscEntry: 'virtual:timber-rsc-entry',
10
+ ssrEntry: 'virtual:timber-ssr-entry',
11
+ browserEntry: 'virtual:timber-browser-entry',
12
+ config: 'virtual:timber-config',
13
+ instrumentation: 'virtual:timber-instrumentation',
14
+ cacheHandler: 'virtual:timber-cache-handler',
15
+ } as const;
@@ -39,7 +39,7 @@ export function onAbortUntil(
39
39
  scope = until;
40
40
  } else {
41
41
  const ended = new AbortController();
42
- const end = (): void => ended.abort();
42
+ const end = (): void => endScope(ended);
43
43
  until.then(end, end);
44
44
  scope = ended.signal;
45
45
  }
@@ -47,3 +47,22 @@ export function onAbortUntil(
47
47
  // scope aborts: the platform's one-step removal, no handle to keep.
48
48
  signal.addEventListener('abort', onAbort, { once: true, signal: scope });
49
49
  }
50
+
51
+ /**
52
+ * The reason every scope controller aborts with. Nothing reads a scope
53
+ * signal's reason (it only removes listeners, through addEventListener's
54
+ * `signal` option), and `abort()` with no reason builds a DOMException, stack
55
+ * trace included, on every call: several per request, ~1.8% of an HTML
56
+ * request's CPU (TIM-1626).
57
+ */
58
+ const SCOPE_ENDED: unique symbol = Symbol('timber.scope-ended');
59
+
60
+ /**
61
+ * End a scope: abort a server-private controller whose signal only bounds
62
+ * listeners (an `onAbortUntil` `until`). Never use it on a signal anything
63
+ * reads a reason from — a render, fetch or stream would see this symbol
64
+ * instead of an AbortError.
65
+ */
66
+ export function endScope(scope: AbortController): void {
67
+ scope.abort(SCOPE_ENDED);
68
+ }
@@ -19,7 +19,7 @@
19
19
  import { Readable, Transform } from 'node:stream';
20
20
  import { NodeBodyResponse } from './node-body-response.ts';
21
21
  import { DEFAULT_MAX_BUFFER_BYTES, teeBufferExceeded } from './stream-utils.ts';
22
- import { onAbortUntil } from './abort-scope.ts';
22
+ import { endScope, onAbortUntil } from './abort-scope.ts';
23
23
  import { RenderTimeoutError } from './render-timeout.ts';
24
24
  import { releaseReason } from './render-utils.ts';
25
25
 
@@ -109,8 +109,17 @@ export function pipeFlightToNode(
109
109
  callback(null, typeof chunk === 'string' ? chunk.toWellFormed() : chunk);
110
110
  },
111
111
  destroy(error, callback) {
112
- scope.abort();
112
+ endScope(scope);
113
113
  clearTimeout(timer);
114
+ // Flight ended the stream (React calls `end()` once the render is
115
+ // complete) and nothing failed: the render is over, so there is
116
+ // nothing to release. Every normally finished render takes this path,
117
+ // and `releaseReason()` would build a DOMException just for React to
118
+ // ignore it (TIM-1626).
119
+ if (error == null && stream.writableEnded) {
120
+ callback(error);
121
+ return;
122
+ }
114
123
  // A no-op once Flight has finished (it ignores abort after close). A
115
124
  // release without a reason aborts with an AbortError, so the render's
116
125
  // onError does not log the abort (releaseReason, TIM-1597).
@@ -18,7 +18,7 @@ import {
18
18
  } from './instrumentation.ts';
19
19
  import { getTraceId } from './tracing.ts';
20
20
  import { requestContextAls } from './als-registry.ts';
21
- import { onAbortUntil } from './abort-scope.ts';
21
+ import { endScope, onAbortUntil } from './abort-scope.ts';
22
22
  import { RedirectSignal } from './primitives.ts';
23
23
  import { isControlFlowSignal } from './signal-identity.ts';
24
24
  import { logRenderError, logSkippedModule, swallow } from './logger.ts';
@@ -535,7 +535,7 @@ export async function runBackgroundFlight<T>(
535
535
  if (!signal.aborted) failed(error);
536
536
  throw error;
537
537
  } finally {
538
- settled.abort();
538
+ endScope(settled);
539
539
  }
540
540
  }
541
541
 
@@ -52,7 +52,7 @@ import { logRenderError, logRouteSetupError } from './logger.ts';
52
52
  import { isDebug } from './debug.ts';
53
53
  import { resolveRenderTimeoutMs } from './render-timeout.ts';
54
54
  import { concatBytes, drainWithDeadline } from './stream-utils.ts';
55
- import { onAbortUntil } from './abort-scope.ts';
55
+ import { endScope, onAbortUntil } from './abort-scope.ts';
56
56
  import type { PipelineConfig, RouteMatch } from './pipeline.ts';
57
57
  import type { MetadataHandler, MetadataRoute } from './types.ts';
58
58
 
@@ -229,7 +229,7 @@ async function bufferResponse(
229
229
  'Metadata route body'
230
230
  );
231
231
  } finally {
232
- readDone.abort();
232
+ endScope(readDone);
233
233
  }
234
234
  const bytes = concatBytes(chunks);
235
235
  const headers = new Headers(response.headers);
@@ -8,7 +8,7 @@
8
8
  * Design doc: 02-rendering-pipeline.md §"Streaming Constraints"
9
9
  */
10
10
 
11
- import { onAbortUntil } from './abort-scope.ts';
11
+ import { endScope, onAbortUntil } from './abort-scope.ts';
12
12
 
13
13
  /** `renderTimeoutMs` when timber.config.ts leaves it unset. */
14
14
  export const DEFAULT_RENDER_TIMEOUT_MS = 30_000;
@@ -75,9 +75,12 @@ export interface RenderTimeout {
75
75
  */
76
76
  export function createRenderTimeout(timeoutMs: number, parentSignal?: AbortSignal): RenderTimeout {
77
77
  const controller = new AbortController();
78
- const reason = new RenderTimeoutError(timeoutMs, 'RSC stream read timed out');
79
-
80
- const timer = setTimeout(() => controller.abort(reason), timeoutMs);
78
+ // The error is built when the timer fires, not up front: almost every
79
+ // render finishes in time, and an Error captures a stack trace.
80
+ const timer = setTimeout(
81
+ () => controller.abort(new RenderTimeoutError(timeoutMs, 'RSC stream read timed out')),
82
+ timeoutMs
83
+ );
81
84
  const scope = new AbortController();
82
85
 
83
86
  // The parent listener lasts until cancel() (server/abort-scope.ts).
@@ -94,7 +97,7 @@ export function createRenderTimeout(timeoutMs: number, parentSignal?: AbortSigna
94
97
  signal: controller.signal,
95
98
  cancel: () => {
96
99
  clearTimeout(timer);
97
- scope.abort();
100
+ endScope(scope);
98
101
  },
99
102
  };
100
103
  }
@@ -88,6 +88,7 @@ import { SlotOutlet } from '../../client/slot-outlet.tsx';
88
88
  import { SlotsProvider } from '../../client/slot-provider.tsx';
89
89
  import { DenyLastResort } from '../../client/deny-last-resort.tsx';
90
90
  import { provideRscViteHandoff } from '../vite-handoff-rsc.ts';
91
+ import { markRouteModulesImmutable } from '../safe-load.ts';
91
92
 
92
93
  // Before anything can render: the runtime reads these at call and render
93
94
  // time through server/vite-handoff-rsc.ts (design/51-native-dev-runtime.md).
@@ -606,4 +607,8 @@ export default _handler!;
606
607
  // This is the boundary @vitejs/plugin-rsc documents for the RSC entry.
607
608
  if (import.meta.hot) {
608
609
  import.meta.hot.accept();
610
+ } else {
611
+ // No dev server can swap route modules: loadModule() may keep them
612
+ // (server/safe-load.ts, TIM-1626).
613
+ markRouteModulesImmutable();
609
614
  }
@@ -36,17 +36,69 @@ export class ModuleLoadError extends Error {
36
36
  }
37
37
  }
38
38
 
39
+ /**
40
+ * Modules already loaded in production, keyed by their manifest loader.
41
+ *
42
+ * Manifest loaders are static objects in the generated manifest module
43
+ * (routing/manifest-codegen.ts), so one loader is one file for the life of
44
+ * the process. A caller that wraps a loader in a fresh object (the sitemap
45
+ * generator does, once per generation) only misses the cache. Node hands back the same namespace on every `import()`, but
46
+ * the round-trip through the loader costs ~2.7µs, and a request loads every
47
+ * layout, page and slot on its path (16 loads on a parallel-routes page):
48
+ * caching measured −4.65% CPU on an HTML page and up to −12.5% on RSC
49
+ * navigation (TIM-1626). A WeakMap hit is ~0.09µs.
50
+ *
51
+ * Only successful loads are stored, so a failed load is retried on the next
52
+ * request and keeps reporting `ModuleLoadError`.
53
+ */
54
+ const loaded = new WeakMap<ManifestLoader, unknown>();
55
+
56
+ /** Set once no dev server can swap route modules; see {@link loadModule}. */
57
+ let routeModulesImmutable = false;
58
+
59
+ /**
60
+ * Declare that route modules cannot change for the life of the process: no
61
+ * dev server's HMR can swap them. Called by the RSC entry when
62
+ * `import.meta.hot` is unset (a built server). Never call it under a dev
63
+ * server, whatever NODE_ENV says.
64
+ */
65
+ export function markRouteModulesImmutable(): void {
66
+ routeModulesImmutable = true;
67
+ }
68
+
39
69
  /**
40
70
  * Load a route manifest module with enriched error context.
41
71
  *
42
72
  * On success: returns the module object (same as `loader.load()`).
43
73
  * On failure: throws `ModuleLoadError` with file path and original cause.
44
74
  *
75
+ * Production builds cache the module per loader. A dev server never does,
76
+ * whatever NODE_ENV says: HMR depends on each request re-importing, so an
77
+ * edited file is picked up, and the manifest (with its loader objects) is
78
+ * not re-evaluated when a route file changes. Both must hold:
79
+ *
80
+ * - `process.env.NODE_ENV === 'production'`, which the server build defines
81
+ * for every adapter, Workers included (plugins/server-bundle.ts). It also
82
+ * keeps vitest (`test`) from caching.
83
+ * - {@link markRouteModulesImmutable} was called. `import.meta.hot` is what
84
+ * says HMR can swap modules, and a dev server started with
85
+ * NODE_ENV=production still has it, but runtime modules cannot read it
86
+ * (they may load outside Vite's module runner, design/51 §"Boundary"), so
87
+ * the RSC entry reads it and calls this, as rsc-entry/ssr-bridge.ts gates
88
+ * the SSR entry.
89
+ *
45
90
  * Error rendering paths that need fallthrough use `loadFallbackModule()`.
46
91
  */
47
92
  export async function loadModule<T = Record<string, unknown>>(loader: ManifestLoader): Promise<T> {
93
+ const cache = process.env.NODE_ENV === 'production' && routeModulesImmutable;
94
+ if (cache) {
95
+ const hit = loaded.get(loader);
96
+ if (hit !== undefined) return hit as T;
97
+ }
48
98
  try {
49
- return (await loader.load()) as T;
99
+ const mod = await loader.load();
100
+ if (cache) loaded.set(loader, mod);
101
+ return mod as T;
50
102
  } catch (error) {
51
103
  throw new ModuleLoadError(loader.filePath, error);
52
104
  }
@@ -304,6 +304,22 @@ function settleOtelSpan<T>(span: Span, fn: () => T | PromiseLike<T>): T | Promis
304
304
  endSpanWithError(span, error);
305
305
  throw error;
306
306
  }
307
+ if (isPlainPromise(result)) {
308
+ // One promise, not two: a plain native promise's `then` cannot throw or
309
+ // run work, so the wrapper below would only add a promise. Dev tracing
310
+ // pays for every promise made inside a render (React's async debug hook
311
+ // captures a stack for each), ~10µs per traced call (TIM-1627).
312
+ return result.then(
313
+ (value) => {
314
+ endSpanOk(span);
315
+ return value;
316
+ },
317
+ (error: unknown) => {
318
+ endSpanWithError(span, error);
319
+ throw error;
320
+ }
321
+ );
322
+ }
307
323
  if (isPromiseLike(result)) {
308
324
  // Any thenable, not only a native Promise — a custom or cross-realm one
309
325
  // must hold the span open too, as `await` would. Its `then` is called
@@ -329,6 +345,19 @@ function settleOtelSpan<T>(span: Span, fn: () => T | PromiseLike<T>): T | Promis
329
345
  return result;
330
346
  }
331
347
 
348
+ /**
349
+ * A native promise of this realm whose `then` is the built-in one: neither a
350
+ * subclass (its `then` may be overridden, and its `then()` constructs the
351
+ * subclass) nor an instance with its own `then` property.
352
+ */
353
+ function isPlainPromise<T>(value: T | PromiseLike<T>): value is Promise<T> {
354
+ return (
355
+ value instanceof Promise &&
356
+ Object.getPrototypeOf(value) === Promise.prototype &&
357
+ !Object.hasOwn(value, 'then')
358
+ );
359
+ }
360
+
332
361
  function isPromiseLike<T>(value: T | PromiseLike<T>): value is PromiseLike<T> {
333
362
  return (
334
363
  (typeof value === 'object' || typeof value === 'function') &&
@@ -5,7 +5,10 @@
5
5
  * Isomorphic: no server, client, or build-time imports.
6
6
  */
7
7
 
8
- /** HMR event that carries one finished span to the browser. */
8
+ /**
9
+ * HMR event that carries finished spans to the browser: a
10
+ * `DevSpanPayload[]` of one trace, in the order the spans ended.
11
+ */
9
12
  export const DEV_SPAN_EVENT = 'timber:span';
10
13
 
11
14
  /** HMR event a tab sends to ask for a trace's spans that ended before it connected. */
@@ -48,6 +51,16 @@ export const AWAIT_WAIT_ATTRIBUTE = 'timber.await_wait';
48
51
  */
49
52
  export const AWAIT_SPAN_MIN_MS = 1;
50
53
 
54
+ /** Span name for one dev-instrumented `fetch()`, ended when headers arrive. */
55
+ export const FETCH_SPAN_NAME = 'timber.fetch';
56
+
57
+ /**
58
+ * Span name for reading a fetched response's body (`.text()`, `.json()`,
59
+ * …), a child of the fetch span. The fetch span ends at headers, so without
60
+ * it a slow body read showed only as the `await res.text()` that waited on it.
61
+ */
62
+ export const FETCH_BODY_SPAN_NAME = 'timber.fetch.body';
63
+
51
64
  /** Root span of every pipeline request. */
52
65
  export const ROOT_SPAN_NAME = 'http.server.request';
53
66
 
@@ -185,7 +198,9 @@ export function devSpanLabel(name: string, attrs: SpanAttributes): { label: stri
185
198
  label: `await ${String(attrs['timber.await_label'] ?? '')}${attrs[AWAIT_WAIT_ATTRIBUTE] === true ? ' (wait)' : ''}`,
186
199
  env: 'await',
187
200
  };
188
- case 'timber.fetch': {
201
+ case FETCH_BODY_SPAN_NAME:
202
+ return { label: 'response body', env: 'fetch' };
203
+ case FETCH_SPAN_NAME: {
189
204
  const fetchMethod = attrs['http.request.method'] ?? 'GET';
190
205
  const fetchUrl = attrs['http.url'] ?? '';
191
206
  return { label: `fetch ${String(fetchMethod)} ${String(fetchUrl)}`, env: 'fetch' };