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

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 (97) hide show
  1. package/dist/_chunks/chains-CmzbpG-6.js +1 -0
  2. package/dist/_chunks/{chains-BsGKkMTK.js → chains-DMoHX4yH.js} +2 -2
  3. package/dist/_chunks/{chains-BsGKkMTK.js.map → chains-DMoHX4yH.js.map} +1 -1
  4. package/dist/_chunks/{classify-cmE0Gins.js → classify-BwyAd-dZ.js} +3 -3
  5. package/dist/_chunks/{classify-cmE0Gins.js.map → classify-BwyAd-dZ.js.map} +1 -1
  6. package/dist/_chunks/{cli-check-BwiahbTC.js → cli-check-DQAD9MLo.js} +3 -3
  7. package/dist/_chunks/{cli-check-BwiahbTC.js.map → cli-check-DQAD9MLo.js.map} +1 -1
  8. package/dist/_chunks/{cli-schema-sync-Brw7kTmm.js → cli-schema-sync-C_xNLqBj.js} +1 -1
  9. package/dist/_chunks/{cli-schema-sync-B2ldclRO.js → cli-schema-sync-CmGls3dc.js} +2 -2
  10. package/dist/_chunks/{cli-schema-sync-B2ldclRO.js.map → cli-schema-sync-CmGls3dc.js.map} +1 -1
  11. package/dist/_chunks/{client-dep-entries-C1nMlLKV.js → client-dep-entries-C5BTQtFS.js} +2 -2
  12. package/dist/_chunks/{client-dep-entries-C1nMlLKV.js.map → client-dep-entries-C5BTQtFS.js.map} +1 -1
  13. package/dist/_chunks/{convention-lint-CLpuzY5h.js → convention-lint-GQA6WTRo.js} +2 -2
  14. package/dist/_chunks/{convention-lint-CLpuzY5h.js.map → convention-lint-GQA6WTRo.js.map} +1 -1
  15. package/dist/_chunks/dev-server--4_Ogy_6.js +1 -0
  16. package/dist/_chunks/{dev-server-lrdpD7Ws.js → dev-server-Cr3_Fu5A.js} +244 -26
  17. package/dist/_chunks/dev-server-Cr3_Fu5A.js.map +1 -0
  18. package/dist/_chunks/dev-span-RsVeYYc_.js.map +1 -1
  19. package/dist/_chunks/{scanner-CrB_h6FA.js → interception-CtNt9jPt.js} +169 -1043
  20. package/dist/_chunks/interception-CtNt9jPt.js.map +1 -0
  21. package/dist/_chunks/{live-graph-ChuFfmLi.js → live-graph-HcLScfiV.js} +4 -4
  22. package/dist/_chunks/{live-graph-ChuFfmLi.js.map → live-graph-HcLScfiV.js.map} +1 -1
  23. package/dist/_chunks/{metadata-routes-BL26HCDd.js → metadata-routes-MXNjWOt5.js} +60 -2
  24. package/dist/_chunks/metadata-routes-MXNjWOt5.js.map +1 -0
  25. package/dist/_chunks/{poison-scan-CJ9QfJWb.js → poison-scan-DONdiCGX.js} +2 -2
  26. package/dist/_chunks/{poison-scan-CJ9QfJWb.js.map → poison-scan-DONdiCGX.js.map} +1 -1
  27. package/dist/_chunks/scanner-DSAJjH0x.js +1043 -0
  28. package/dist/_chunks/scanner-DSAJjH0x.js.map +1 -0
  29. package/dist/_chunks/{walkers-BUvpsb2Q.js → walkers-96YopJds.js} +3 -3
  30. package/dist/_chunks/{walkers-BUvpsb2Q.js.map → walkers-96YopJds.js.map} +1 -1
  31. package/dist/analyze/crawl-entry.js +3 -3
  32. package/dist/analyze/graph-command.js +2 -2
  33. package/dist/cli.js +3 -3
  34. package/dist/config-types.d.ts +11 -0
  35. package/dist/config-types.d.ts.map +1 -1
  36. package/dist/config-validation.d.ts.map +1 -1
  37. package/dist/dev-tools/instrumentation.d.ts.map +1 -1
  38. package/dist/dev-tools/log-columns.d.ts +50 -0
  39. package/dist/dev-tools/log-columns.d.ts.map +1 -0
  40. package/dist/dev-tools/logger.d.ts +5 -0
  41. package/dist/dev-tools/logger.d.ts.map +1 -1
  42. package/dist/index.js +6 -155
  43. package/dist/index.js.map +1 -1
  44. package/dist/native/rsc/dev-tools/instrumentation.js +5 -1
  45. package/dist/native/rsc/dev-tools/instrumentation.js.map +1 -1
  46. package/dist/native/rsc/dev-tools/log-columns.js +69 -0
  47. package/dist/native/rsc/dev-tools/log-columns.js.map +1 -0
  48. package/dist/native/rsc/dev-tools/logger.js +60 -33
  49. package/dist/native/rsc/dev-tools/logger.js.map +1 -1
  50. package/dist/native/rsc/manifest.json +1 -0
  51. package/dist/native/rsc/shared/dev-span.js +5 -2
  52. package/dist/native/rsc/shared/dev-span.js.map +1 -1
  53. package/dist/native/rsc/shared/span-waterfall.js +13 -2
  54. package/dist/native/rsc/shared/span-waterfall.js.map +1 -1
  55. package/dist/native/ssr/dev-tools/instrumentation.js +5 -1
  56. package/dist/native/ssr/dev-tools/instrumentation.js.map +1 -1
  57. package/dist/native/ssr/dev-tools/log-columns.js +69 -0
  58. package/dist/native/ssr/dev-tools/log-columns.js.map +1 -0
  59. package/dist/native/ssr/dev-tools/logger.js +60 -33
  60. package/dist/native/ssr/dev-tools/logger.js.map +1 -1
  61. package/dist/native/ssr/manifest.json +1 -0
  62. package/dist/native/ssr/shared/dev-span.js +5 -2
  63. package/dist/native/ssr/shared/dev-span.js.map +1 -1
  64. package/dist/native/ssr/shared/span-waterfall.js +13 -2
  65. package/dist/native/ssr/shared/span-waterfall.js.map +1 -1
  66. package/dist/plugins/dev-precompile.d.ts +42 -14
  67. package/dist/plugins/dev-precompile.d.ts.map +1 -1
  68. package/dist/plugins/dev-server.d.ts.map +1 -1
  69. package/dist/routing/index.js +3 -2
  70. package/dist/routing/manifest-codegen.d.ts +2 -0
  71. package/dist/routing/manifest-codegen.d.ts.map +1 -1
  72. package/dist/server/internal.js +1 -2
  73. package/dist/server/internal.js.map +1 -1
  74. package/dist/shared/dev-span.d.ts +6 -0
  75. package/dist/shared/dev-span.d.ts.map +1 -1
  76. package/dist/shared/span-waterfall.d.ts.map +1 -1
  77. package/docs/api/34-api-config.mdx +18 -0
  78. package/package.json +1 -1
  79. package/src/config-types.ts +11 -0
  80. package/src/config-validation.ts +15 -8
  81. package/src/dev-tools/instrumentation.ts +4 -1
  82. package/src/dev-tools/log-columns.ts +156 -0
  83. package/src/dev-tools/logger.ts +107 -63
  84. package/src/plugins/dev-precompile.ts +108 -20
  85. package/src/plugins/dev-server.ts +12 -11
  86. package/src/routing/manifest-codegen.ts +2 -2
  87. package/src/shared/dev-span.ts +13 -1
  88. package/src/shared/span-waterfall.ts +36 -4
  89. package/dist/_chunks/chains-DHmoKxkO.js +0 -1
  90. package/dist/_chunks/dev-server-BGGGhHXx.js +0 -1
  91. package/dist/_chunks/dev-server-lrdpD7Ws.js.map +0 -1
  92. package/dist/_chunks/metadata-routes-BL26HCDd.js.map +0 -1
  93. package/dist/_chunks/scanner-CrB_h6FA.js.map +0 -1
  94. package/dist/_chunks/segment-keys-Y60KNc8C.js +0 -61
  95. package/dist/_chunks/segment-keys-Y60KNc8C.js.map +0 -1
  96. package/dist/_chunks/tree-match-Bqdr9szG.js +0 -168
  97. package/dist/_chunks/tree-match-Bqdr9szG.js.map +0 -1
@@ -13,9 +13,15 @@
13
13
  * - `env.transformRequest()` only: nothing executes, so the app's
14
14
  * instrumentation `register()` and cache handler setup still run at the
15
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.
16
+ * - Static imports only (`result.deps`), from the entries and every module
17
+ * file in the route tree ({@link routeTreeSeeds}). Route files are dynamic
18
+ * imports of the route manifest, which the crawl does not follow, so they
19
+ * are seeded directly. Crawling only the root layout left most of an app
20
+ * whose UI sits in route groups and slots to the first request: on
21
+ * relisten-web it covered 53 of the 499 SSR modules `GET /` needed, and the
22
+ * whole route tree (~960 modules) takes ~1.6s (TIM-1630).
23
+ * - In waves: what `GET /` can load first, RSC then SSR, so the
24
+ * most common first request is ready soonest; then the rest.
19
25
  * - Errors are swallowed. The request that loads the module hits the same
20
26
  * error and reports it as it always has; Vite's `warmupRequest` was
21
27
  * rejected because it logs each error a second time.
@@ -28,30 +34,99 @@
28
34
  *
29
35
  * `analyze/crawl.ts` also walks `transformRequest`, for a different job:
30
36
  * 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.
37
+ * a throwaway middleware-mode server.
38
+ *
39
+ * `dev.precompile: false` in timber.config, or `TIMBER_DEV_PRECOMPILE=0`,
40
+ * turns it off.
33
41
  *
34
42
  * See design/21-dev-server.md §"Server Pre-compile".
35
43
  */
36
44
 
37
45
  import { normalizePath, type DevEnvironment, type ViteDevServer } from 'vite';
38
46
  import type { PluginApi } from '@vitejs/plugin-rsc';
47
+ import type { RouteFile, RouteTree, SegmentNode } from '../routing/types.ts';
48
+ import { RECORD_FILE_KEYS, SINGLE_FILE_KEYS } from '../routing/manifest-codegen.ts';
49
+ import { isStaticMetadataExtension } from '../server/metadata-routes.ts';
39
50
 
40
51
  /** `TIMBER_DEV_PRECOMPILE=0` turns the crawl off (A/B measurement, escape hatch). */
41
52
  export const PRECOMPILE_ENV = 'TIMBER_DEV_PRECOMPILE';
42
53
 
43
54
  /**
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.
55
+ * Past this, the crawl starts no new transform. Generous: the whole route
56
+ * tree takes ~1.6s on relisten-web. It bounds a crawl stuck behind a slow
57
+ * transform plugin, or an app too large to finish.
46
58
  */
47
59
  export const PRECOMPILE_DEADLINE_MS = 60_000;
48
60
 
49
- /** The roots of each server environment's crawl. */
61
+ /**
62
+ * The roots of each server environment's crawl. `rsc` is crawled in waves,
63
+ * in order; after each wave the SSR environment crawls `ssr` and every
64
+ * client reference recorded so far.
65
+ */
50
66
  export interface PrecompileRoots {
51
- rsc: string[];
67
+ rsc: string[][];
52
68
  ssr: string[];
53
69
  }
54
70
 
71
+ /**
72
+ * Segment types whose subtree can match its parent's URL: they consume no
73
+ * URL segment (or none, for an empty optional catch-all).
74
+ */
75
+ const PATHLESS = new Set(['group', 'optional-catch-all']);
76
+
77
+ /** `node`, or a pathless segment under it, has a page or handler for its URL. */
78
+ function rendersOwnPath(node: SegmentNode): boolean {
79
+ if (node.page || node.route) return true;
80
+ return node.children.some((child) => PATHLESS.has(child.segmentType) && rendersOwnPath(child));
81
+ }
82
+
83
+ /**
84
+ * The files of a segment that the runtime loads as modules: every file the
85
+ * route manifest lists for it (routing/manifest-codegen.ts, so a convention
86
+ * the manifest learns is crawled too), except JSON status files and static
87
+ * metadata files (`sitemap.xml`, `icon.png`, …), which are read from disk
88
+ * and never imported.
89
+ */
90
+ function segmentFiles(node: SegmentNode): RouteFile[] {
91
+ const files: RouteFile[] = [];
92
+ for (const key of SINGLE_FILE_KEYS) {
93
+ const file = node[key];
94
+ if (file) files.push(file);
95
+ }
96
+ for (const key of RECORD_FILE_KEYS) {
97
+ if (key === 'jsonStatusFiles') continue;
98
+ for (const [name, file] of Object.entries(node[key] ?? {})) {
99
+ if (key === 'metadataRoutes' && isStaticMetadataExtension(name, file.extension)) continue;
100
+ files.push(file);
101
+ }
102
+ }
103
+ return files;
104
+ }
105
+
106
+ /**
107
+ * Every module file in the route tree, in two waves. `home` is what `GET /`
108
+ * can load: `proxy.ts`, `global-error`, the root segment, and under it the
109
+ * pathless segments (groups, optional catch-alls) with a page or handler at
110
+ * `/`, and the slots of those. A group that only organises other sections
111
+ * (`(admin)/admin/…`) is not in it. `rest` is every other segment's.
112
+ */
113
+ export function routeTreeSeeds(tree: RouteTree): { home: string[]; rest: string[] } {
114
+ const home: string[] = [];
115
+ const rest: string[] = [];
116
+ for (const file of [tree.proxy, tree.globalError]) if (file) home.push(file.filePath);
117
+ const walk = (node: SegmentNode, inHome: boolean): void => {
118
+ for (const file of segmentFiles(node)) (inHome ? home : rest).push(file.filePath);
119
+ for (const child of node.children) {
120
+ walk(child, inHome && PATHLESS.has(child.segmentType) && rendersOwnPath(child));
121
+ }
122
+ // A slot renders beside its parent's page, so it is in whichever wave
123
+ // its parent is.
124
+ for (const slot of Object.values(node.slots)) walk(slot, inHome);
125
+ };
126
+ walk(tree.root, true);
127
+ return { home, rest };
128
+ }
129
+
55
130
  /**
56
131
  * The id `transformRequest` takes for an entry of `result.deps`, or null for
57
132
  * one it must not follow: a bare specifier, which in a server environment is
@@ -85,14 +160,17 @@ export function fileUrl(file: string, root: string): string {
85
160
  /**
86
161
  * Transform `roots` and every module they statically import in `env`.
87
162
  * Starts no transform once `shouldStop()` is true. Resolves with the
88
- * number of modules visited once the graph is done; never rejects.
163
+ * number of ids in `seen` (every module visited in `env` so far, across
164
+ * crawls that share it) once the graph is done; never rejects. `seen`
165
+ * carries visited ids across crawls of one environment, so a later wave
166
+ * skips what an earlier one transformed.
89
167
  */
90
168
  export async function crawlServerGraph(
91
169
  env: DevEnvironment,
92
170
  roots: string[],
93
- shouldStop: () => boolean = () => false
171
+ shouldStop: () => boolean = () => false,
172
+ seen: Set<string> = new Set()
94
173
  ): Promise<number> {
95
- const seen = new Set<string>();
96
174
  const visit = async (id: string): Promise<void> => {
97
175
  if (seen.has(id) || shouldStop()) return;
98
176
  seen.add(id);
@@ -115,8 +193,8 @@ export async function crawlServerGraph(
115
193
 
116
194
  /**
117
195
  * 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
196
+ * references, by the id plugin-rsc registered for it. Read after each RSC
197
+ * wave: plugin-rsc records a client reference when it transforms
120
198
  * the `'use client'` module in the RSC environment.
121
199
  */
122
200
  function clientReferenceIds(server: ViteDevServer): string[] {
@@ -134,9 +212,9 @@ function clientReferenceIds(server: ViteDevServer): string[] {
134
212
  }
135
213
 
136
214
  /**
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.
215
+ * For each RSC wave, crawl the RSC graph, then the SSR graph with the client
216
+ * references found so far. A request that arrives mid-crawl shares the
217
+ * transforms already in flight for the URLs it asks for.
140
218
  */
141
219
  export async function precompileServerGraphs(
142
220
  server: ViteDevServer,
@@ -144,9 +222,19 @@ export async function precompileServerGraphs(
144
222
  shouldStop: () => boolean
145
223
  ): Promise<void> {
146
224
  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);
225
+ const rscSeen = new Set<string>();
226
+ const ssrSeen = new Set<string>();
227
+ for (const wave of roots.rsc) {
228
+ if (shouldStop()) return;
229
+ if (rsc) await crawlServerGraph(rsc, wave, shouldStop, rscSeen);
230
+ if (ssr && !shouldStop()) {
231
+ await crawlServerGraph(
232
+ ssr,
233
+ [...roots.ssr, ...clientReferenceIds(server)],
234
+ shouldStop,
235
+ ssrSeen
236
+ );
237
+ }
150
238
  }
151
239
  }
152
240
 
@@ -39,7 +39,7 @@ 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';
42
+ import { fileUrl, precompileOnListen, routeTreeSeeds } from './dev-precompile.ts';
43
43
  import { VIRTUAL_IDS } from './virtual-ids.ts';
44
44
  import { advertisedUrls, applyDevHostname } from './dev-hostname.ts';
45
45
  import {
@@ -312,16 +312,17 @@ export function timberDevServer(ctx: PluginContext): Plugin {
312
312
 
313
313
  // Transform the server graphs in the background once listening, so
314
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
- });
315
+ // design/21 §Server Pre-compile. `dev.precompile: false` opts out.
316
+ if (ctx.config.dev?.precompile !== false) {
317
+ precompileOnListen(server, () => {
318
+ const toUrl = (file: string) => fileUrl(file, server.config.root);
319
+ const seeds = ctx.routeTree ? routeTreeSeeds(ctx.routeTree) : { home: [], rest: [] };
320
+ return {
321
+ rsc: [[VIRTUAL_IDS.rscEntry, ...seeds.home.map(toUrl)], seeds.rest.map(toUrl)],
322
+ ssr: [VIRTUAL_IDS.ssrEntry],
323
+ };
324
+ });
325
+ }
325
326
 
326
327
  // Close the holding server and await the port release so Vite's
327
328
  // port probe and bind see a free port. configureServer is awaited
@@ -16,7 +16,7 @@ import type { RouteTree, SegmentNode, RouteFile } from './types.ts';
16
16
  // ── Single-file conventions ─────────────────────────────────────────────
17
17
  // Each entry maps to a node property that holds a single RouteFile.
18
18
  // Order matches the original serializeNode output for byte-identical diffs.
19
- const SINGLE_FILE_KEYS = [
19
+ export const SINGLE_FILE_KEYS = [
20
20
  'page',
21
21
  'layout',
22
22
  'middleware',
@@ -29,7 +29,7 @@ const SINGLE_FILE_KEYS = [
29
29
 
30
30
  // ── Record-shaped conventions ───────────────────────────────────────────
31
31
  // Each entry maps to a node property that holds Record<string, RouteFile>.
32
- const RECORD_FILE_KEYS = ['statusFiles', 'jsonStatusFiles', 'metadataRoutes'] as const;
32
+ export const RECORD_FILE_KEYS = ['statusFiles', 'jsonStatusFiles', 'metadataRoutes'] as const;
33
33
 
34
34
  const SCHEMA_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
35
35
 
@@ -154,6 +154,15 @@ function slotPrefix(attrs: SpanAttributes): string {
154
154
  return slot ? `${String(slot)} ` : '';
155
155
  }
156
156
 
157
+ /**
158
+ * A fetch URL as the terminal tree and the pill show it: without its scheme,
159
+ * which is `https://` for nearly every fetch and only makes the line longer
160
+ * (TIM-1631).
161
+ */
162
+ export function fetchDisplayUrl(url: string): string {
163
+ return url.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '');
164
+ }
165
+
157
166
  /**
158
167
  * Map a span to its display label and environment tag. One mapping for the
159
168
  * terminal tree and the dev request pill, so the two never name a span
@@ -203,7 +212,10 @@ export function devSpanLabel(name: string, attrs: SpanAttributes): { label: stri
203
212
  case FETCH_SPAN_NAME: {
204
213
  const fetchMethod = attrs['http.request.method'] ?? 'GET';
205
214
  const fetchUrl = attrs['http.url'] ?? '';
206
- return { label: `fetch ${String(fetchMethod)} ${String(fetchUrl)}`, env: 'fetch' };
215
+ return {
216
+ label: `fetch ${String(fetchMethod)} ${fetchDisplayUrl(String(fetchUrl))}`,
217
+ env: 'fetch',
218
+ };
207
219
  }
208
220
  default:
209
221
  return { label: name, env: 'rsc' };
@@ -177,10 +177,38 @@ export function buildWaterfall<T extends WaterfallSpan>(
177
177
  const hidden = (s: T) => hideWaits && waits.has(s.spanId);
178
178
 
179
179
  /** Shown children, with an unkept child's shown descendants in its place. */
180
- const visibleChildren = (parent: string | undefined): T[] =>
180
+ const shownUnder = (parent: string | undefined): T[] =>
181
181
  (children.get(parent) ?? []).flatMap((s) =>
182
- hidden(s) ? [] : kept(s) ? [s] : visibleChildren(s.spanId)
182
+ hidden(s) ? [] : kept(s) ? [s] : shownUnder(s.spanId)
183
183
  );
184
+ /**
185
+ * The same, in start order: a skipped span's descendants are drawn among
186
+ * its siblings by when they started, not at the skipped span's place (a
187
+ * sub-1ms layout's pages above an await that started 1.6s earlier,
188
+ * TIM-1631).
189
+ */
190
+ const visibleChildren = (parent: string | undefined): T[] =>
191
+ shownUnder(parent).sort((a, b) => a.startMs - b.startMs);
192
+
193
+ /**
194
+ * When a span's I/O ended: its own end, or later through the awaits,
195
+ * fetches and body reads under it. A fetch span ends at the headers and its
196
+ * body read is a child, so a fetch's I/O runs to the end of the read, even
197
+ * when the read happens after the `await fetch(url)` around it returned.
198
+ * Waits and framework spans don't count: they did no I/O of their own.
199
+ */
200
+ const ioEnds = new Map<string, number>();
201
+ const ioEnd = (span: T): number => {
202
+ let end = ioEnds.get(span.spanId);
203
+ if (end === undefined) {
204
+ const io = (children.get(span.spanId) ?? []).filter(
205
+ (kid) => IO_SPANS.has(kid.name) && kid.attributes[AWAIT_WAIT_ATTRIBUTE] !== true
206
+ );
207
+ end = Math.max(span.endMs, ...io.map(ioEnd));
208
+ ioEnds.set(span.spanId, end);
209
+ }
210
+ return end;
211
+ };
184
212
 
185
213
  const origin = Math.min(...spans.map((s) => s.startMs));
186
214
  const rows: WaterfallRow<T>[] = [];
@@ -192,7 +220,11 @@ export function buildWaterfall<T extends WaterfallSpan>(
192
220
  // dimmed row, not vanish into its parent. A child that outlives its
193
221
  // parent (a fetch raced against a timeout) never folds either: the row
194
222
  // draws the parent's interval, which would drop the rest of the child's
195
- // time. Codex review on #1288.
223
+ // time. Codex review on #1288. Coverage counts the child's I/O through
224
+ // the parent's end, so a loader whose fetch spent most of its time on the
225
+ // body read still folds into it (TIM-1631). A body read after the parent
226
+ // returned (`await fetch(url)`, then `res.json()` elsewhere) is the
227
+ // fetch's own row's business, drawn beside it, not a reason not to fold.
196
228
  const foldable = (kid: T | undefined): kid is T =>
197
229
  kid !== undefined &&
198
230
  !waits.has(kid.spanId) &&
@@ -200,7 +232,7 @@ export function buildWaterfall<T extends WaterfallSpan>(
200
232
  (kid.name === AWAIT_SPAN_NAME && !IO_SPANS.has(tail.name))) &&
201
233
  kid.startMs >= tail.startMs &&
202
234
  kid.endMs <= tail.endMs &&
203
- duration(kid) >= FOLD_COVERAGE * duration(tail);
235
+ Math.min(ioEnd(kid), tail.endMs) - kid.startMs >= FOLD_COVERAGE * duration(tail);
204
236
  if (fold && !expanded.has(span.spanId)) {
205
237
  for (
206
238
  let only = kids.length === 1 ? kids[0] : undefined;
@@ -1 +0,0 @@
1
- export { t as formatChains } from "./chains-BsGKkMTK.js";
@@ -1 +0,0 @@
1
- export { t as RESTART_EXIT_CODE } from "./dev-server-lrdpD7Ws.js";