@timber-js/app 0.2.0-alpha.235 → 0.2.0-alpha.236
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{actions-CYjRMpZI.js → actions-Top9GftB.js} +3 -3
- package/dist/_chunks/{actions-CYjRMpZI.js.map → actions-Top9GftB.js.map} +1 -1
- package/dist/_chunks/{cache-api-BZJNt01a.js → cache-api-Bo8c7XVF.js} +6 -6
- package/dist/_chunks/{cache-api-BZJNt01a.js.map → cache-api-Bo8c7XVF.js.map} +1 -1
- package/dist/_chunks/{chains-D-RRc7CM.js → chains-BsGKkMTK.js} +2 -2
- package/dist/_chunks/{chains-D-RRc7CM.js.map → chains-BsGKkMTK.js.map} +1 -1
- package/dist/_chunks/chains-DHmoKxkO.js +1 -0
- package/dist/_chunks/{classify-_W0RWa5w.js → classify-cmE0Gins.js} +2 -2
- package/dist/_chunks/{classify-_W0RWa5w.js.map → classify-cmE0Gins.js.map} +1 -1
- package/dist/_chunks/{cli-check-Dl3yo3Zv.js → cli-check-BwiahbTC.js} +3 -3
- package/dist/_chunks/{cli-check-Dl3yo3Zv.js.map → cli-check-BwiahbTC.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CyrOHbAo.js → cli-schema-sync-B2ldclRO.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-CyrOHbAo.js.map → cli-schema-sync-B2ldclRO.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CTWiBMZZ.js → cli-schema-sync-Brw7kTmm.js} +1 -1
- package/dist/_chunks/{client-dep-entries-C9hv-3k9.js → client-dep-entries-C1nMlLKV.js} +2 -2
- package/dist/_chunks/{client-dep-entries-C9hv-3k9.js.map → client-dep-entries-C1nMlLKV.js.map} +1 -1
- package/dist/_chunks/{cloudflare-_2fhxQE8.js → cloudflare-Dk5Hqo-O.js} +3 -3
- package/dist/_chunks/{cloudflare-_2fhxQE8.js.map → cloudflare-Dk5Hqo-O.js.map} +1 -1
- package/dist/_chunks/{convention-lint-D54k6uUM.js → convention-lint-CLpuzY5h.js} +3 -3
- package/dist/_chunks/{convention-lint-D54k6uUM.js.map → convention-lint-CLpuzY5h.js.map} +1 -1
- package/dist/_chunks/dev-server-BGGGhHXx.js +1 -0
- package/dist/_chunks/{dev-server-cmWVDgTf.js → dev-server-lrdpD7Ws.js} +121 -5
- package/dist/_chunks/dev-server-lrdpD7Ws.js.map +1 -0
- package/dist/_chunks/{dev-span-_NzMX-au.js → dev-span-RsVeYYc_.js} +5 -2
- package/dist/_chunks/dev-span-RsVeYYc_.js.map +1 -0
- package/dist/_chunks/{error-boundary-Cf1m-Ywk.js → error-boundary-Bh-egWUI.js} +6 -6
- package/dist/_chunks/{error-boundary-Cf1m-Ywk.js.map → error-boundary-Bh-egWUI.js.map} +1 -1
- package/dist/_chunks/{flight-source-node-BGanuoSS.js → flight-source-node-BO_xD9jC.js} +2 -2
- package/dist/_chunks/{flight-source-node-BGanuoSS.js.map → flight-source-node-BO_xD9jC.js.map} +1 -1
- package/dist/_chunks/{href-BtspoNc9.js → href-8l5VD23D.js} +2 -2
- package/dist/_chunks/{href-BtspoNc9.js.map → href-8l5VD23D.js.map} +1 -1
- package/dist/_chunks/{json-lossy-check-BXM45k8p.js → json-lossy-check-D47R9Fp5.js} +2 -2
- package/dist/_chunks/{json-lossy-check-BXM45k8p.js.map → json-lossy-check-D47R9Fp5.js.map} +1 -1
- package/dist/_chunks/{live-graph-C7-yA8W9.js → live-graph-ChuFfmLi.js} +4 -4
- package/dist/_chunks/{live-graph-C7-yA8W9.js.map → live-graph-ChuFfmLi.js.map} +1 -1
- package/dist/_chunks/{logger-YtMSKfft.js → logger-DDLtp5e-.js} +16 -1
- package/dist/_chunks/logger-DDLtp5e-.js.map +1 -0
- package/dist/_chunks/navigation-root-Cvb7P1ud.js.map +1 -1
- package/dist/_chunks/{node-response-D3hXWb8y.js → node-response-DNNnKnoS.js} +2 -2
- package/dist/_chunks/{node-response-D3hXWb8y.js.map → node-response-DNNnKnoS.js.map} +1 -1
- package/dist/_chunks/{poison-scan-CRSP06Es.js → poison-scan-CJ9QfJWb.js} +2 -2
- package/dist/_chunks/{poison-scan-CRSP06Es.js.map → poison-scan-CJ9QfJWb.js.map} +1 -1
- package/dist/_chunks/{scanner-BNQ4qnLX.js → scanner-CrB_h6FA.js} +5 -5
- package/dist/_chunks/{scanner-BNQ4qnLX.js.map → scanner-CrB_h6FA.js.map} +1 -1
- package/dist/_chunks/{sizeof-Cmx6Fs-Y.js → sizeof-DVhEVN_y.js} +2 -2
- package/dist/_chunks/{sizeof-Cmx6Fs-Y.js.map → sizeof-DVhEVN_y.js.map} +1 -1
- package/dist/_chunks/{walkers-DFC9KsBL.js → walkers-BUvpsb2Q.js} +3 -3
- package/dist/_chunks/{walkers-DFC9KsBL.js.map → walkers-BUvpsb2Q.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +2 -2
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/nitro.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +3 -3
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/dev-pill/index.d.ts +2 -1
- package/dist/client/dev-pill/index.d.ts.map +1 -1
- package/dist/client/dev-pill/view.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +4 -4
- package/dist/client/internal.js +3 -3
- package/dist/cookies/index.js +1 -1
- package/dist/dev-tools/await-span.d.ts +7 -0
- package/dist/dev-tools/await-span.d.ts.map +1 -1
- package/dist/dev-tools/instrumentation.d.ts.map +1 -1
- package/dist/dev-tools/logger.d.ts +8 -2
- package/dist/dev-tools/logger.d.ts.map +1 -1
- package/dist/dev-tools/span-sink.d.ts +9 -1
- package/dist/dev-tools/span-sink.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -31
- package/dist/index.js.map +1 -1
- 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
- package/dist/native/rsc/_react/flight-client.js +2 -2
- package/dist/native/rsc/_react/flight-server.js +1 -1
- package/dist/native/rsc/_react/flight-static.js +1 -1
- package/dist/native/rsc/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/native/rsc/adapters/cloudflare.js +2 -2
- package/dist/native/rsc/cache/cache-api.js +3 -3
- package/dist/native/rsc/cache/index.js +3 -3
- package/dist/native/rsc/cache/timber-cache.js +2 -2
- package/dist/native/rsc/cdn/index.js +1 -1
- package/dist/native/rsc/client/use-cookie.js +1 -1
- package/dist/native/rsc/dev-tools/404-page.js +1 -1
- package/dist/native/rsc/dev-tools/await-span.js +5 -2
- package/dist/native/rsc/dev-tools/await-span.js.map +1 -1
- package/dist/native/rsc/dev-tools/error-page.js +2 -2
- package/dist/native/rsc/dev-tools/instrumentation.js +38 -3
- package/dist/native/rsc/dev-tools/instrumentation.js.map +1 -1
- package/dist/native/rsc/dev-tools/logger.js +123 -80
- package/dist/native/rsc/dev-tools/logger.js.map +1 -1
- package/dist/native/rsc/dev-tools/span-sink.js +1 -0
- package/dist/native/rsc/dev-tools/span-sink.js.map +1 -1
- package/dist/native/rsc/dev-tools/terminal.js +1 -1
- package/dist/native/rsc/manifest.json +1 -0
- package/dist/native/rsc/params/index.js +1 -1
- package/dist/native/rsc/routing/collision-probe.js +1 -1
- package/dist/native/rsc/routing/interception.js +1 -1
- package/dist/native/rsc/search-params/define.js +2 -2
- package/dist/native/rsc/server/access-gate.js +1 -1
- package/dist/native/rsc/server/action-client.js +2 -2
- package/dist/native/rsc/server/action-handler.js +8 -8
- package/dist/native/rsc/server/actions.js +3 -3
- package/dist/native/rsc/server/children-interception.js +1 -1
- package/dist/native/rsc/server/deny-boundary.js +1 -1
- package/dist/native/rsc/server/deny-renderer.js +10 -10
- package/dist/native/rsc/server/fallback-error.js +1 -1
- package/dist/native/rsc/server/flight-injector-core.js +2 -2
- package/dist/native/rsc/server/flight-source-node.js +2 -2
- package/dist/native/rsc/server/index.js +4 -4
- package/dist/native/rsc/server/interception-gates.js +2 -2
- package/dist/native/rsc/server/internal.js +15 -15
- package/dist/native/rsc/server/logger.js +2 -2
- package/dist/native/rsc/server/metadata-route-links.js +1 -1
- package/dist/native/rsc/server/node-body-response.js +1 -1
- package/dist/native/rsc/server/param-coercion.js +1 -1
- package/dist/native/rsc/server/pipeline-helpers.js +10 -10
- package/dist/native/rsc/server/pipeline-interception.js +4 -4
- package/dist/native/rsc/server/pipeline-metadata-route.js +10 -10
- package/dist/native/rsc/server/pipeline-outcome.js +4 -4
- package/dist/native/rsc/server/pipeline-phases.js +11 -11
- package/dist/native/rsc/server/pipeline.js +10 -10
- package/dist/native/rsc/server/prebuilt/capture-render.js +1 -1
- package/dist/native/rsc/server/prebuilt/dev-store.js +1 -1
- package/dist/native/rsc/server/prebuilt/overlay.js +3 -3
- package/dist/native/rsc/server/prebuilt-builder.js +8 -8
- package/dist/native/rsc/server/prebuilt-runtime.js +15 -15
- package/dist/native/rsc/server/primitives.js +2 -2
- package/dist/native/rsc/server/publish-params.js +1 -1
- package/dist/native/rsc/server/request-context.js +1 -1
- package/dist/native/rsc/server/route-element-builder.js +7 -7
- package/dist/native/rsc/server/route-element-helpers.js +1 -1
- package/dist/native/rsc/server/route-handler.js +1 -1
- package/dist/native/rsc/server/rsc-entry/action-dispatcher.js +1 -1
- package/dist/native/rsc/server/rsc-entry/action-middleware-runner.js +1 -1
- package/dist/native/rsc/server/rsc-entry/api-handler.js +1 -1
- package/dist/native/rsc/server/rsc-entry/deny-fallback.js +6 -6
- package/dist/native/rsc/server/rsc-entry/error-renderer.js +7 -7
- package/dist/native/rsc/server/rsc-entry/helpers.js +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +4 -4
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +7 -7
- package/dist/native/rsc/server/rsc-entry/rsc-payload.js +3 -3
- package/dist/native/rsc/server/rsc-entry/rsc-stream.js +6 -6
- package/dist/native/rsc/server/rsc-entry/ssr-renderer.js +10 -10
- package/dist/native/rsc/server/rsc-error-envelope.js +1 -1
- package/dist/native/rsc/server/sitemap-handler.js +1 -1
- package/dist/native/rsc/server/skippable-prefix.js +2 -2
- package/dist/native/rsc/server/slot-interception.js +1 -1
- package/dist/native/rsc/server/slot-resolver.js +11 -11
- package/dist/native/rsc/server/static-generator.js +2 -2
- package/dist/native/rsc/server/traced-access.js +1 -1
- package/dist/native/rsc/server/tracing.js +10 -0
- package/dist/native/rsc/server/tracing.js.map +1 -1
- package/dist/native/rsc/shared/dev-span.js +8 -2
- package/dist/native/rsc/shared/dev-span.js.map +1 -1
- package/dist/native/rsc/shared/href.js +1 -1
- package/dist/native/rsc/shared/span-waterfall.js +90 -0
- package/dist/native/rsc/shared/span-waterfall.js.map +1 -0
- package/dist/native/ssr/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/native/ssr/adapters/cloudflare.js +2 -2
- package/dist/native/ssr/cache/cache-api.js +3 -3
- package/dist/native/ssr/cache/guarded-read.js +1 -1
- package/dist/native/ssr/cache/index.js +3 -3
- package/dist/native/ssr/cache/timber-cache.js +3 -3
- package/dist/native/ssr/cdn/index.js +1 -1
- package/dist/native/ssr/client/error-boundary.js +1 -1
- package/dist/native/ssr/client/index.js +5 -5
- package/dist/native/ssr/client/link.js +5 -5
- package/dist/native/ssr/client/navigation-commit.js +2 -2
- package/dist/native/ssr/client/nuqs-adapter.js +2 -2
- package/dist/native/ssr/client/params-context.js +1 -1
- package/dist/native/ssr/client/router-skew.js +1 -1
- package/dist/native/ssr/client/rsc-fetch.js +2 -2
- package/dist/native/ssr/client/use-pending-navigation.js +1 -1
- package/dist/native/ssr/client/use-search-params.js +2 -2
- package/dist/native/ssr/client/use-segment-params.js +1 -1
- package/dist/native/ssr/client/use-selected-layout-segment.js +1 -1
- package/dist/native/ssr/dev-tools/await-span.js +5 -2
- package/dist/native/ssr/dev-tools/await-span.js.map +1 -1
- package/dist/native/ssr/dev-tools/instrumentation.js +38 -3
- package/dist/native/ssr/dev-tools/instrumentation.js.map +1 -1
- package/dist/native/ssr/dev-tools/logger.js +123 -80
- package/dist/native/ssr/dev-tools/logger.js.map +1 -1
- package/dist/native/ssr/dev-tools/span-sink.js +1 -0
- package/dist/native/ssr/dev-tools/span-sink.js.map +1 -1
- package/dist/native/ssr/manifest.json +1 -0
- package/dist/native/ssr/params/index.js +1 -1
- package/dist/native/ssr/search-params/define.js +2 -2
- package/dist/native/ssr/server/access-gate.js +1 -1
- package/dist/native/ssr/server/action-client.js +2 -2
- package/dist/native/ssr/server/actions.js +3 -3
- package/dist/native/ssr/server/deny-boundary.js +2 -2
- package/dist/native/ssr/server/flight-injector-core.js +1 -1
- package/dist/native/ssr/server/flight-source-node.js +2 -2
- package/dist/native/ssr/server/index.js +4 -4
- package/dist/native/ssr/server/internal.js +12 -12
- package/dist/native/ssr/server/logger.js +2 -2
- package/dist/native/ssr/server/node-body-response.js +1 -1
- package/dist/native/ssr/server/node-stream-transforms.js +2 -2
- package/dist/native/ssr/server/param-coercion.js +3 -3
- package/dist/native/ssr/server/pipeline-helpers.js +7 -7
- package/dist/native/ssr/server/pipeline-interception.js +4 -4
- package/dist/native/ssr/server/pipeline-metadata-route.js +10 -10
- package/dist/native/ssr/server/pipeline-outcome.js +4 -4
- package/dist/native/ssr/server/pipeline-phases.js +10 -10
- package/dist/native/ssr/server/pipeline.js +10 -10
- package/dist/native/ssr/server/prebuilt/capture-render.js +2 -2
- package/dist/native/ssr/server/prebuilt/dev-store.js +1 -1
- package/dist/native/ssr/server/prebuilt/overlay.js +4 -4
- package/dist/native/ssr/server/prebuilt-runtime.js +14 -14
- package/dist/native/ssr/server/primitives.js +2 -2
- package/dist/native/ssr/server/request-context.js +2 -2
- package/dist/native/ssr/server/route-handler.js +1 -1
- package/dist/native/ssr/server/rsc-error-envelope.js +1 -1
- package/dist/native/ssr/server/ssr-form-state.js +2 -2
- package/dist/native/ssr/server/ssr-wrappers.js +1 -1
- package/dist/native/ssr/server/traced-access.js +1 -1
- package/dist/native/ssr/server/tracing.js +10 -0
- package/dist/native/ssr/server/tracing.js.map +1 -1
- package/dist/native/ssr/shared/dev-span.js +8 -2
- package/dist/native/ssr/shared/dev-span.js.map +1 -1
- package/dist/native/ssr/shared/href.js +1 -1
- package/dist/native/ssr/shared/span-waterfall.js +90 -0
- package/dist/native/ssr/shared/span-waterfall.js.map +1 -0
- package/dist/plugins/dev-precompile.d.ts +84 -0
- package/dist/plugins/dev-precompile.d.ts.map +1 -0
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/virtual-ids.d.ts +16 -0
- package/dist/plugins/virtual-ids.d.ts.map +1 -0
- package/dist/routes/index.js +1 -1
- package/dist/routing/index.js +3 -3
- package/dist/search-params/index.js +2 -2
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +14 -14
- package/dist/server/tracing.d.ts.map +1 -1
- package/dist/shared/dev-span.d.ts +12 -1
- package/dist/shared/dev-span.d.ts.map +1 -1
- package/dist/shared/span-waterfall.d.ts +88 -0
- package/dist/shared/span-waterfall.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/client/dev-pill/index.ts +5 -2
- package/src/client/dev-pill/store.ts +1 -1
- package/src/client/dev-pill/view.ts +15 -5
- package/src/dev-tools/await-span.ts +10 -0
- package/src/dev-tools/instrumentation.ts +44 -6
- package/src/dev-tools/logger.ts +230 -155
- package/src/dev-tools/span-sink.ts +34 -3
- package/src/index.ts +21 -11
- package/src/plugins/dev-precompile.ts +168 -0
- package/src/plugins/dev-server.ts +16 -3
- package/src/plugins/entries.ts +1 -11
- package/src/plugins/virtual-ids.ts +15 -0
- package/src/server/tracing.ts +29 -0
- package/src/shared/dev-span.ts +17 -2
- package/src/{client/dev-pill/waterfall.ts → shared/span-waterfall.ts} +84 -51
- package/dist/_chunks/chains-KblEfYzm.js +0 -1
- package/dist/_chunks/dev-server-DrYBIg66.js +0 -1
- package/dist/_chunks/dev-server-cmWVDgTf.js.map +0 -1
- package/dist/_chunks/dev-span-_NzMX-au.js.map +0 -1
- package/dist/_chunks/logger-YtMSKfft.js.map +0 -1
- package/dist/client/dev-pill/waterfall.d.ts +0 -64
- package/dist/client/dev-pill/waterfall.d.ts.map +0 -1
package/src/index.ts
CHANGED
|
@@ -199,19 +199,27 @@ function createRscOptions(
|
|
|
199
199
|
* output mode to be silently ignored. See TIM-451.
|
|
200
200
|
*/
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
202
|
+
* Adjust plugin-react's `vite:react-compiler` plugin:
|
|
203
|
+
*
|
|
204
|
+
* - Its configResolved always sees `isProduction: true` during builds. The
|
|
205
|
+
* compiler plugin uses `!config.isProduction` to decide whether to emit
|
|
206
|
+
* jsxDEV calls, but Vite derives isProduction from process.env.NODE_ENV —
|
|
207
|
+
* which may be "development" in the shell. Rather than mutating the env,
|
|
208
|
+
* we pass a prototype-based view with the single property overridden.
|
|
209
|
+
* - In dev it runs on the client environment only. Its `shouldCompile`
|
|
210
|
+
* requires a client environment, so on rsc/ssr it only repeats the
|
|
211
|
+
* JSX/TS transform `vite:oxc` does next, plus a sourcemap: ~200ms of a
|
|
212
|
+
* ~2.4s cold kitchen-sink request. Output is the same except for a
|
|
213
|
+
* trailing semicolon in plugin-rsc's CSS stubs (TIM-1627).
|
|
214
|
+
* Builds keep it on every environment, unchanged.
|
|
208
215
|
*/
|
|
209
|
-
function
|
|
216
|
+
function patchReactCompiler(plugins: PluginOption[]): PluginOption[] {
|
|
210
217
|
for (const p of plugins) {
|
|
211
218
|
if (p && typeof p === 'object' && 'name' in p && p.name === 'vite:react-compiler') {
|
|
212
|
-
const
|
|
219
|
+
const plugin = p as Plugin;
|
|
220
|
+
const orig = plugin.configResolved;
|
|
213
221
|
if (typeof orig === 'function') {
|
|
214
|
-
|
|
222
|
+
plugin.configResolved = function (config) {
|
|
215
223
|
const view =
|
|
216
224
|
config.command === 'build' && !config.isProduction
|
|
217
225
|
? Object.create(config, { isProduction: { value: true } })
|
|
@@ -219,6 +227,8 @@ function patchReactCompilerForProdJsx(plugins: PluginOption[]): PluginOption[] {
|
|
|
219
227
|
return orig.call(this, view);
|
|
220
228
|
};
|
|
221
229
|
}
|
|
230
|
+
plugin.applyToEnvironment = (env) =>
|
|
231
|
+
env.config.command === 'build' || env.config.consumer === 'client';
|
|
222
232
|
}
|
|
223
233
|
}
|
|
224
234
|
return plugins;
|
|
@@ -331,7 +341,7 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
331
341
|
// and Vite's built-in OXC transform emits jsxDEV calls (the
|
|
332
342
|
// production jsx-runtime doesn't export jsxDEV). The oxc.jsx
|
|
333
343
|
// override below fixes Vite's native path; plugin-react's compiler
|
|
334
|
-
// plugin is handled by
|
|
344
|
+
// plugin is handled by patchReactCompiler above.
|
|
335
345
|
// ── Resolve dev port (TIM-842) ───────────────────────────────
|
|
336
346
|
// Default port is 3000. Vite handles conflicts and honors server.strictPort.
|
|
337
347
|
// We start the holding server on the requested port when available.
|
|
@@ -567,7 +577,7 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
567
577
|
// for client components via Babel transform. Placed before @vitejs/plugin-rsc
|
|
568
578
|
// following Vinext's convention — the RSC plugin's virtual browser entry
|
|
569
579
|
// coordinates with plugin-react via __vite_plugin_react_preamble_installed__.
|
|
570
|
-
...
|
|
580
|
+
...patchReactCompiler(
|
|
571
581
|
react({
|
|
572
582
|
compiler: (effectiveReactCompiler || false) as boolean | ReactCompilerOptions,
|
|
573
583
|
})
|
|
@@ -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(
|
|
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
|
package/src/plugins/entries.ts
CHANGED
|
@@ -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;
|
package/src/server/tracing.ts
CHANGED
|
@@ -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') &&
|
package/src/shared/dev-span.ts
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* Isomorphic: no server, client, or build-time imports.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/**
|
|
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
|
|
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' };
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A trace's spans as rows to read: the dev request pill's waterfall and the
|
|
3
|
+
* terminal tree.
|
|
3
4
|
*
|
|
4
|
-
* Pure: spans in, rows out.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Pure: spans in, rows out. Built to be read, not to mirror the span tree.
|
|
6
|
+
* Waits whose work other rows already show can be hidden, and pass-through
|
|
7
|
+
* wrappers can fold into the row they wrap. One implementation for both
|
|
8
|
+
* surfaces, so the pill and the terminal never disagree about which awaits
|
|
9
|
+
* are noise. See design/50-dev-request-pill.md §"Reading the awaits view".
|
|
10
|
+
*
|
|
11
|
+
* Isomorphic: no server, client, or build-time imports.
|
|
8
12
|
*/
|
|
9
13
|
|
|
10
14
|
import {
|
|
11
15
|
AWAIT_SPAN_NAME,
|
|
12
16
|
AWAIT_WAIT_ATTRIBUTE,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** Every span, or only the I/O: awaits and fetches. */
|
|
17
|
-
export type WaterfallView = 'all' | 'awaits';
|
|
17
|
+
FETCH_BODY_SPAN_NAME,
|
|
18
|
+
FETCH_SPAN_NAME,
|
|
19
|
+
} from './dev-span.ts';
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
const IO_SPANS = new Set([AWAIT_SPAN_NAME, FETCH_SPAN_NAME]);
|
|
21
|
+
/** The I/O: awaits, fetches, and fetched bodies being read. */
|
|
22
|
+
const IO_SPANS = new Set([AWAIT_SPAN_NAME, FETCH_SPAN_NAME, FETCH_BODY_SPAN_NAME]);
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* A wait is explained when spans outside its own ancestry cover this much
|
|
@@ -31,19 +33,38 @@ const WAIT_COVERAGE = 0.8;
|
|
|
31
33
|
*/
|
|
32
34
|
const FOLD_COVERAGE = 0.9;
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* What the rules read from a span. The pill's `DevSpanPayload` and the
|
|
38
|
+
* terminal's projection of an OTEL `ReadableSpan` both satisfy it.
|
|
39
|
+
*/
|
|
40
|
+
export interface WaterfallSpan {
|
|
41
|
+
spanId: string;
|
|
42
|
+
/** Absent, or not among the spans, for a top-level span. */
|
|
43
|
+
parentSpanId?: string;
|
|
44
|
+
name: string;
|
|
45
|
+
startMs: number;
|
|
46
|
+
endMs: number;
|
|
47
|
+
attributes: Readonly<Record<string, unknown>>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface WaterfallOptions<T extends WaterfallSpan = WaterfallSpan> {
|
|
51
|
+
/** Keep only the I/O, awaits and fetches (the pill's awaits view). */
|
|
52
|
+
ioOnly?: boolean;
|
|
53
|
+
/** Spans to leave out, with their shown children in their place. */
|
|
54
|
+
skip?: (span: T) => boolean;
|
|
55
|
+
/** Leave out waits other spans explain. */
|
|
56
|
+
hideWaits?: boolean;
|
|
57
|
+
/** Fold pass-through awaits into the row they wrap. */
|
|
58
|
+
fold?: boolean;
|
|
38
59
|
/** Rows the user unfolded, by the outer span's ID. */
|
|
39
60
|
expanded?: ReadonlySet<string>;
|
|
40
61
|
}
|
|
41
62
|
|
|
42
|
-
export interface WaterfallRow {
|
|
63
|
+
export interface WaterfallRow<T extends WaterfallSpan> {
|
|
43
64
|
/** The row's outermost span: its position, depth and location. */
|
|
44
|
-
span:
|
|
65
|
+
span: T;
|
|
45
66
|
/** Spans folded into this row, outermost first. Empty when nothing folded. */
|
|
46
|
-
folded:
|
|
67
|
+
folded: T[];
|
|
47
68
|
/** An explained wait: shown only on request, and dimmed. */
|
|
48
69
|
wait: boolean;
|
|
49
70
|
depth: number;
|
|
@@ -52,13 +73,13 @@ export interface WaterfallRow {
|
|
|
52
73
|
durationMs: number;
|
|
53
74
|
}
|
|
54
75
|
|
|
55
|
-
export interface Waterfall {
|
|
56
|
-
rows: WaterfallRow[];
|
|
76
|
+
export interface Waterfall<T extends WaterfallSpan> {
|
|
77
|
+
rows: WaterfallRow<T>[];
|
|
57
78
|
/** Explained waits left out of `rows`. */
|
|
58
79
|
hiddenWaits: number;
|
|
59
80
|
}
|
|
60
81
|
|
|
61
|
-
const duration = (s:
|
|
82
|
+
const duration = (s: WaterfallSpan) => s.endMs - s.startMs;
|
|
62
83
|
|
|
63
84
|
/** Total length of the union of [start, end) intervals. */
|
|
64
85
|
function unionLength(intervals: Array<[number, number]>): number {
|
|
@@ -85,10 +106,10 @@ function unionLength(intervals: Array<[number, number]>): number {
|
|
|
85
106
|
* A wait with children started work after all (a getter that returns a new
|
|
86
107
|
* promise), so it counts as work too.
|
|
87
108
|
*/
|
|
88
|
-
export function explainedWaits(spans: readonly
|
|
109
|
+
export function explainedWaits(spans: readonly WaterfallSpan[]): Set<string> {
|
|
89
110
|
const byId = new Map(spans.map((s) => [s.spanId, s]));
|
|
90
111
|
const parents = new Set(spans.map((s) => s.parentSpanId));
|
|
91
|
-
const isCandidate = (s:
|
|
112
|
+
const isCandidate = (s: WaterfallSpan) =>
|
|
92
113
|
s.attributes[AWAIT_WAIT_ATTRIBUTE] === true && !parents.has(s.spanId);
|
|
93
114
|
const work = spans.filter((s) => IO_SPANS.has(s.name) && !isCandidate(s));
|
|
94
115
|
const explained = new Set<string>();
|
|
@@ -112,24 +133,35 @@ export function explainedWaits(spans: readonly DevSpanPayload[]): Set<string> {
|
|
|
112
133
|
|
|
113
134
|
/**
|
|
114
135
|
* Spans in tree order (parent before children, siblings by start). The time
|
|
115
|
-
* axis starts at the trace's first span
|
|
116
|
-
*
|
|
117
|
-
* `view: 'awaits'` keeps only awaits and fetches, each nested under its
|
|
118
|
-
* nearest kept ancestor, so hiding framework phases leaves no gaps in the
|
|
119
|
-
* indentation. On top of that:
|
|
136
|
+
* axis starts at the trace's first span.
|
|
120
137
|
*
|
|
121
|
-
* -
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
138
|
+
* - `ioOnly` keeps only awaits and fetches, each nested under its nearest
|
|
139
|
+
* kept ancestor, so hiding framework phases leaves no gaps in the
|
|
140
|
+
* indentation.
|
|
141
|
+
* - `hideWaits` leaves out explained waits, with their children (they have
|
|
142
|
+
* none: a wait with children isn't explained).
|
|
143
|
+
* - `skip` leaves out the spans it matches, like `ioOnly` does.
|
|
144
|
+
* - `fold`: an await whose only shown child takes nearly all its time folds
|
|
145
|
+
* into one row with that child (unless the child is a wait), repeatedly,
|
|
146
|
+
* so `loadShow → def.load → fetch` is one row. So does a framework span
|
|
147
|
+
* into an only child that is an await (`proxy.ts → await next()`), which
|
|
148
|
+
* only arises when framework spans are shown. A fetch folds nothing. A
|
|
149
|
+
* row in `expanded`
|
|
150
|
+
* doesn't fold.
|
|
125
151
|
*/
|
|
126
|
-
export function buildWaterfall(
|
|
127
|
-
spans: readonly
|
|
128
|
-
{
|
|
129
|
-
|
|
152
|
+
export function buildWaterfall<T extends WaterfallSpan>(
|
|
153
|
+
spans: readonly T[],
|
|
154
|
+
{
|
|
155
|
+
ioOnly = false,
|
|
156
|
+
skip,
|
|
157
|
+
hideWaits = false,
|
|
158
|
+
fold = false,
|
|
159
|
+
expanded = new Set<string>(),
|
|
160
|
+
}: WaterfallOptions<T> = {}
|
|
161
|
+
): Waterfall<T> {
|
|
130
162
|
if (spans.length === 0) return { rows: [], hiddenWaits: 0 };
|
|
131
163
|
const ids = new Set(spans.map((s) => s.spanId));
|
|
132
|
-
const children = new Map<string | undefined,
|
|
164
|
+
const children = new Map<string | undefined, T[]>();
|
|
133
165
|
for (const span of spans) {
|
|
134
166
|
// A span whose parent isn't here (the root still open, or a parent
|
|
135
167
|
// outside this trace's spans) sits at the top level.
|
|
@@ -141,19 +173,19 @@ export function buildWaterfall(
|
|
|
141
173
|
for (const siblings of children.values()) siblings.sort((a, b) => a.startMs - b.startMs);
|
|
142
174
|
|
|
143
175
|
const waits = explainedWaits(spans);
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const shown = (s: DevSpanPayload) =>
|
|
147
|
-
!awaitsView || (IO_SPANS.has(s.name) && !(hideWaits && waits.has(s.spanId)));
|
|
176
|
+
const kept = (s: T) => (!ioOnly || IO_SPANS.has(s.name)) && !skip?.(s);
|
|
177
|
+
const hidden = (s: T) => hideWaits && waits.has(s.spanId);
|
|
148
178
|
|
|
149
|
-
/** Shown children, with
|
|
150
|
-
const visibleChildren = (parent: string | undefined):
|
|
151
|
-
(children.get(parent) ?? []).flatMap((s) =>
|
|
179
|
+
/** Shown children, with an unkept child's shown descendants in its place. */
|
|
180
|
+
const visibleChildren = (parent: string | undefined): T[] =>
|
|
181
|
+
(children.get(parent) ?? []).flatMap((s) =>
|
|
182
|
+
hidden(s) ? [] : kept(s) ? [s] : visibleChildren(s.spanId)
|
|
183
|
+
);
|
|
152
184
|
|
|
153
185
|
const origin = Math.min(...spans.map((s) => s.startMs));
|
|
154
|
-
const rows: WaterfallRow[] = [];
|
|
155
|
-
const emit = (span:
|
|
156
|
-
const folded:
|
|
186
|
+
const rows: WaterfallRow<T>[] = [];
|
|
187
|
+
const emit = (span: T, depth: number) => {
|
|
188
|
+
const folded: T[] = [];
|
|
157
189
|
let tail = span;
|
|
158
190
|
let kids = visibleChildren(tail.spanId);
|
|
159
191
|
// A wait never folds: shown on request, it must appear as its own,
|
|
@@ -161,14 +193,15 @@ export function buildWaterfall(
|
|
|
161
193
|
// parent (a fetch raced against a timeout) never folds either: the row
|
|
162
194
|
// draws the parent's interval, which would drop the rest of the child's
|
|
163
195
|
// time. Codex review on #1288.
|
|
164
|
-
const foldable = (kid:
|
|
196
|
+
const foldable = (kid: T | undefined): kid is T =>
|
|
165
197
|
kid !== undefined &&
|
|
166
198
|
!waits.has(kid.spanId) &&
|
|
167
|
-
tail.name === AWAIT_SPAN_NAME
|
|
199
|
+
(tail.name === AWAIT_SPAN_NAME ||
|
|
200
|
+
(kid.name === AWAIT_SPAN_NAME && !IO_SPANS.has(tail.name))) &&
|
|
168
201
|
kid.startMs >= tail.startMs &&
|
|
169
202
|
kid.endMs <= tail.endMs &&
|
|
170
203
|
duration(kid) >= FOLD_COVERAGE * duration(tail);
|
|
171
|
-
if (
|
|
204
|
+
if (fold && !expanded.has(span.spanId)) {
|
|
172
205
|
for (
|
|
173
206
|
let only = kids.length === 1 ? kids[0] : undefined;
|
|
174
207
|
foldable(only);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { t as formatChains } from "./chains-D-RRc7CM.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { t as RESTART_EXIT_CODE } from "./dev-server-cmWVDgTf.js";
|