@timber-js/app 0.2.0-alpha.234 → 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-BAKOSTkg.js → cli-check-BwiahbTC.js} +5 -5
- package/dist/_chunks/{cli-check-BAKOSTkg.js.map → cli-check-BwiahbTC.js.map} +1 -1
- package/dist/_chunks/{cli-context-BPdyA7Fp.js → cli-context-BbwVqarO.js} +1 -1
- package/dist/_chunks/{cli-context-CwTKMjVe.js → cli-context-DZh5v0yd.js} +2 -2
- package/dist/_chunks/{cli-context-CwTKMjVe.js.map → cli-context-DZh5v0yd.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CAllbqRB.js → cli-schema-sync-B2ldclRO.js} +3 -3
- package/dist/_chunks/{cli-schema-sync-CAllbqRB.js.map → cli-schema-sync-B2ldclRO.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-y_8ijmzO.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-Rq659RR1.js → dev-server-lrdpD7Ws.js} +122 -6
- 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/{plugin-context-FCkaNLUB.js → plugin-context-BtaQcMuh.js} +2 -2
- package/dist/_chunks/{plugin-context-FCkaNLUB.js.map → plugin-context-BtaQcMuh.js.map} +1 -1
- package/dist/_chunks/{plugin-context-BfSRKJfz.js → plugin-context-I1dvGccO.js} +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-D_QHR_nf.js → walkers-BUvpsb2Q.js} +3 -3
- package/dist/_chunks/{walkers-D_QHR_nf.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 +4 -4
- package/dist/analyze/graph-command.js +5 -5
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cli.js +6 -6
- 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/store.d.ts +0 -18
- package/dist/client/dev-pill/store.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 +12 -1
- 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 +183 -40
- 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 +10 -7
- 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 +2 -2
- 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 +11 -4
- 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 +10 -7
- 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 +11 -4
- 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-await.d.ts +3 -0
- package/dist/plugins/dev-await.d.ts.map +1 -1
- 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/native-runtime.d.ts +2 -2
- package/dist/plugins/native-runtime.d.ts.map +1 -1
- package/dist/plugins/plugin-rsc-package.d.ts +35 -0
- package/dist/plugins/plugin-rsc-package.d.ts.map +1 -0
- 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 +21 -3
- 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 +3 -3
- package/src/client/dev-pill/index.ts +5 -2
- package/src/client/dev-pill/store.ts +5 -64
- package/src/client/dev-pill/view.ts +175 -53
- package/src/dev-tools/await-span.ts +32 -13
- 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 +24 -21
- package/src/plugins/dev-await.ts +61 -3
- 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/native-runtime.ts +4 -3
- package/src/plugins/plugin-rsc-package.ts +81 -0
- package/src/plugins/virtual-ids.ts +15 -0
- package/src/server/tracing.ts +29 -0
- package/src/shared/dev-span.ts +29 -6
- package/src/shared/span-waterfall.ts +227 -0
- package/dist/_chunks/chains-KblEfYzm.js +0 -1
- package/dist/_chunks/dev-server-L8biS7Az.js +0 -1
- package/dist/_chunks/dev-server-Rq659RR1.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/src/index.ts
CHANGED
|
@@ -14,7 +14,6 @@ import type { Plugin, PluginOption } from 'vite';
|
|
|
14
14
|
import type { ReactCompilerOptions } from '@vitejs/plugin-react';
|
|
15
15
|
import { createLogger } from 'vite';
|
|
16
16
|
import { join, relative, resolve } from 'node:path';
|
|
17
|
-
import { createRequire } from 'node:module';
|
|
18
17
|
import react from '@vitejs/plugin-react';
|
|
19
18
|
import { timberContent } from './plugins/content.ts';
|
|
20
19
|
import { timberDevServer } from './plugins/dev-server.ts';
|
|
@@ -38,6 +37,7 @@ import { timberRequestDep } from './plugins/request-dep/index.ts';
|
|
|
38
37
|
import { timberOptimizePackageImports } from './plugins/optimize-package-imports.ts';
|
|
39
38
|
import { timberClientInServerPackageDeps } from './plugins/client-in-server-package-deps.ts';
|
|
40
39
|
import { timberNodeFlightBuilds } from './plugins/node-flight-builds.ts';
|
|
40
|
+
import { loadPluginRsc, timberPluginRscDeps } from './plugins/plugin-rsc-package.ts';
|
|
41
41
|
import { timberNativeRuntime } from './plugins/native-runtime.ts';
|
|
42
42
|
import { timberPrebuilt } from './plugins/prebuilt.ts';
|
|
43
43
|
import { timberPrerenderSugar } from './plugins/prerender-sugar.ts';
|
|
@@ -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;
|
|
@@ -227,17 +237,9 @@ function patchReactCompilerForProdJsx(plugins: PluginOption[]): PluginOption[] {
|
|
|
227
237
|
export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
228
238
|
const ctx = createPluginContext(config);
|
|
229
239
|
|
|
230
|
-
// Resolve dependencies from the consumer's project (process.cwd()),
|
|
231
|
-
// not from timber's own node_modules. This is critical for pnpm link:
|
|
232
|
-
// when linked, timber's node_modules has a separate vite instance, and
|
|
233
|
-
// the RSC plugin must use the same vite instance as the dev server.
|
|
234
|
-
const consumerRequire = createRequire(join(process.cwd(), 'package.json'));
|
|
235
|
-
|
|
236
240
|
// ── Step 1: Load @vitejs/plugin-rsc ─────────────────────────────────
|
|
237
|
-
// Synchronous require() works for ESM modules on Node 22.12+.
|
|
238
241
|
ctx.timer.start('rsc-plugin-import');
|
|
239
|
-
const
|
|
240
|
-
const vitePluginRsc = rscMod.default ?? rscMod;
|
|
242
|
+
const vitePluginRsc = loadPluginRsc(process.cwd());
|
|
241
243
|
ctx.timer.end('rsc-plugin-import');
|
|
242
244
|
|
|
243
245
|
// ── Step 2: Compute config-dependent options ────────────────────────
|
|
@@ -339,7 +341,7 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
339
341
|
// and Vite's built-in OXC transform emits jsxDEV calls (the
|
|
340
342
|
// production jsx-runtime doesn't export jsxDEV). The oxc.jsx
|
|
341
343
|
// override below fixes Vite's native path; plugin-react's compiler
|
|
342
|
-
// plugin is handled by
|
|
344
|
+
// plugin is handled by patchReactCompiler above.
|
|
343
345
|
// ── Resolve dev port (TIM-842) ───────────────────────────────
|
|
344
346
|
// Default port is 3000. Vite handles conflicts and honors server.strictPort.
|
|
345
347
|
// We start the holding server on the requested port when available.
|
|
@@ -569,12 +571,13 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
569
571
|
timberReactResolve(),
|
|
570
572
|
timberNodeFlightBuilds(), // Dev: one (Node, pre-bundled) Flight build per server environment
|
|
571
573
|
timberNativeRuntime(), // Dev, installed timber: load the runtime natively (design/51)
|
|
574
|
+
timberPluginRscDeps(), // Dev, installed timber: pre-bundle plugin-rsc's deps through timber
|
|
572
575
|
timberReactProd(),
|
|
573
576
|
// @vitejs/plugin-react provides React Fast Refresh (state-preserving HMR)
|
|
574
577
|
// for client components via Babel transform. Placed before @vitejs/plugin-rsc
|
|
575
578
|
// following Vinext's convention — the RSC plugin's virtual browser entry
|
|
576
579
|
// coordinates with plugin-react via __vite_plugin_react_preamble_installed__.
|
|
577
|
-
...
|
|
580
|
+
...patchReactCompiler(
|
|
578
581
|
react({
|
|
579
582
|
compiler: (effectiveReactCompiler || false) as boolean | ReactCompilerOptions,
|
|
580
583
|
})
|
package/src/plugins/dev-await.ts
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* const rows = await __timber_await$(() => (db.select().from(users)),
|
|
10
10
|
* "db.select().from(users)", "app/users/page.tsx:12");
|
|
11
11
|
*
|
|
12
|
+
* An operand that starts no work (`await call`, `await Promise.all([a, b])`)
|
|
13
|
+
* gets a fourth argument, `true`, so the wrapper can mark the await a wait.
|
|
14
|
+
*
|
|
12
15
|
* `__timber_await$` is declared once per module and looks the wrapper up on
|
|
13
16
|
* `globalThis[DEV_AWAIT_KEY]` at call time (installed with dev tracing,
|
|
14
17
|
* `dev-tools/await-span.ts`); with none installed it calls the thunk. A
|
|
@@ -89,6 +92,60 @@ function containsAwait(node: Node): boolean {
|
|
|
89
92
|
return children(node).some(containsAwait);
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
/** Wrappers that change nothing about what the operand is. */
|
|
96
|
+
const TRANSPARENT_TYPES = new Set([
|
|
97
|
+
'ParenthesizedExpression',
|
|
98
|
+
'TSAsExpression',
|
|
99
|
+
'TSSatisfiesExpression',
|
|
100
|
+
'TSNonNullExpression',
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
const PROMISE_COMBINATORS = new Set(['all', 'allSettled', 'any', 'race']);
|
|
104
|
+
|
|
105
|
+
/** `p`, `this.p`, `state.pending?.p`: a value that already exists. */
|
|
106
|
+
function isReference(node: Node): boolean {
|
|
107
|
+
if (TRANSPARENT_TYPES.has(node.type) && isNode(node.expression)) {
|
|
108
|
+
return isReference(node.expression);
|
|
109
|
+
}
|
|
110
|
+
if (node.type === 'ChainExpression' && isNode(node.expression)) {
|
|
111
|
+
return isReference(node.expression);
|
|
112
|
+
}
|
|
113
|
+
return node.type === 'Identifier' || node.type === 'MemberExpression';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The operand starts no work of its own: it reads a promise that already
|
|
118
|
+
* exists (`await call`, `await this.pending`), or combines such promises
|
|
119
|
+
* (`await Promise.all([a, b])`). The work began when the promise was made,
|
|
120
|
+
* so its spans nest wherever that happened, not under this await. The
|
|
121
|
+
* wrapper marks the await a wait if the value is a native promise; a getter
|
|
122
|
+
* that starts work shows up as a wait with children, which the pill treats
|
|
123
|
+
* as work.
|
|
124
|
+
*/
|
|
125
|
+
function startsNoWork(node: Node): boolean {
|
|
126
|
+
if (TRANSPARENT_TYPES.has(node.type) && isNode(node.expression)) {
|
|
127
|
+
return startsNoWork(node.expression);
|
|
128
|
+
}
|
|
129
|
+
if (isReference(node)) return true;
|
|
130
|
+
if (node.type !== 'CallExpression') return false;
|
|
131
|
+
const callee = node.callee;
|
|
132
|
+
const args = (node.arguments as Node[] | undefined) ?? [];
|
|
133
|
+
const array = args[0];
|
|
134
|
+
return (
|
|
135
|
+
isNode(callee) &&
|
|
136
|
+
callee.type === 'MemberExpression' &&
|
|
137
|
+
isNode(callee.object) &&
|
|
138
|
+
callee.object.type === 'Identifier' &&
|
|
139
|
+
callee.object.name === 'Promise' &&
|
|
140
|
+
isNode(callee.property) &&
|
|
141
|
+
PROMISE_COMBINATORS.has(String(callee.property.name)) &&
|
|
142
|
+
args.length === 1 &&
|
|
143
|
+
isNode(array) &&
|
|
144
|
+
array.type === 'ArrayExpression' &&
|
|
145
|
+
((array.elements as unknown[] | undefined) ?? []).every((e) => isNode(e) && isReference(e))
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
92
149
|
/** Parser dialect for a module path: the transform sees original source. */
|
|
93
150
|
export function langFor(file: string): 'ts' | 'tsx' | 'jsx' {
|
|
94
151
|
if (/\.tsx$/.test(file)) return 'tsx';
|
|
@@ -313,7 +370,8 @@ export function instrumentAwaits(
|
|
|
313
370
|
// (React.cache, an in-flight load) from new work.
|
|
314
371
|
const thunk = containsAwait(arg) ? 'async () => (' : '() => (';
|
|
315
372
|
s.prependRight(arg.start, `${HELPER}(${thunk}`);
|
|
316
|
-
|
|
373
|
+
const wait = startsNoWork(arg) ? ', true' : '';
|
|
374
|
+
s.appendLeft(arg.end, `), ${text}, ${location}${wait})`);
|
|
317
375
|
count++;
|
|
318
376
|
};
|
|
319
377
|
visit(program, false);
|
|
@@ -322,8 +380,8 @@ export function instrumentAwaits(
|
|
|
322
380
|
// After the directive prologue — a statement before `'use server'` would
|
|
323
381
|
// demote it to a plain string.
|
|
324
382
|
const helper =
|
|
325
|
-
`\nconst ${HELPER} = (f, l, c) => ` +
|
|
326
|
-
`(globalThis[Symbol.for("timber.dev.await")] ?? ((g) => g()))(f, l, c);\n`;
|
|
383
|
+
`\nconst ${HELPER} = (f, l, c, w) => ` +
|
|
384
|
+
`(globalThis[Symbol.for("timber.dev.await")] ?? ((g) => g()))(f, l, c, w);\n`;
|
|
327
385
|
s.appendLeft(prologue.end, helper);
|
|
328
386
|
|
|
329
387
|
return { code: s.toString(), map: s.generateMap({ hires: true }) };
|
|
@@ -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
|
*
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
* `__vite_rsc_require__`, so a global alias stands in for it.
|
|
31
31
|
*
|
|
32
32
|
* Used only when timber runs from an installed package with its mirrors, and
|
|
33
|
-
* `TIMBER_DEV_NATIVE_RUNTIME` is not `0`; RSC also needs the app's React
|
|
34
|
-
* react-dom
|
|
33
|
+
* `TIMBER_DEV_NATIVE_RUNTIME` is not `0`; RSC also needs the app's React and
|
|
34
|
+
* react-dom to be the versions the mirror bundled, and falls
|
|
35
35
|
* back to Vite with a warning otherwise (design/51 §"Two dev paths").
|
|
36
36
|
* timber's own repo and examples alias `@timber-js/app` to `src/` and keep the
|
|
37
37
|
* Vite path.
|
|
@@ -44,6 +44,7 @@ import { parseAst, type Plugin } from 'vite';
|
|
|
44
44
|
import MagicString from 'magic-string';
|
|
45
45
|
|
|
46
46
|
import { SRC_DIR } from './entries.ts';
|
|
47
|
+
import { isInstalledPackage } from './plugin-rsc-package.ts';
|
|
47
48
|
import {
|
|
48
49
|
NATIVE_MANIFEST_FILE,
|
|
49
50
|
type NativeManifest,
|
|
@@ -98,7 +99,7 @@ export function decideNativeRuntime(
|
|
|
98
99
|
if (env.TIMBER_DEV_NATIVE_RUNTIME === '0') return everywhere('TIMBER_DEV_NATIVE_RUNTIME=0');
|
|
99
100
|
// An installed package. timber's repo, its examples and linked apps run
|
|
100
101
|
// src/ through Vite, where edits to timber itself hot-reload.
|
|
101
|
-
if (!srcDir
|
|
102
|
+
if (!isInstalledPackage(srcDir)) {
|
|
102
103
|
return everywhere('timber is not an installed package');
|
|
103
104
|
}
|
|
104
105
|
const decision: NativeRuntimeDecision = { manifests: {}, vitePath: {}, warn: false };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which copy of `@vitejs/plugin-rsc` timber runs, and the one Vite setting
|
|
3
|
+
* that follows from it.
|
|
4
|
+
*
|
|
5
|
+
* plugin-rsc is a dependency of `@timber-js/app`, pinned exactly: apps never
|
|
6
|
+
* import it, and the RSC mirror bundles that version's Flight runtime
|
|
7
|
+
* (design/51-native-dev-runtime.md). So:
|
|
8
|
+
*
|
|
9
|
+
* - **An installed timber loads its own copy.** The plugin, the runtime that
|
|
10
|
+
* timber's modules import and the bundled Flight runtime are then one
|
|
11
|
+
* version, whatever else the app installed. Package managers give that copy
|
|
12
|
+
* the app's Vite through timber's `vite` peer.
|
|
13
|
+
* - **A linked or from-source timber loads the app's copy.** It has its own
|
|
14
|
+
* `node_modules` with its own Vite, and plugin-rsc checks environments
|
|
15
|
+
* against the Vite it imports (`vite.isRunnableDevEnvironment`), so a copy
|
|
16
|
+
* resolved from timber would see a second Vite. This repo's examples and
|
|
17
|
+
* `pnpm link` setups take this path, with plugin-rsc installed in the
|
|
18
|
+
* workspace or the app.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { createRequire } from 'node:module';
|
|
22
|
+
import { join, sep } from 'node:path';
|
|
23
|
+
import type { Plugin } from 'vite';
|
|
24
|
+
|
|
25
|
+
import { SRC_DIR } from './entries.ts';
|
|
26
|
+
|
|
27
|
+
const PLUGIN_RSC = '@vitejs/plugin-rsc';
|
|
28
|
+
|
|
29
|
+
/** Whether timber's `src/` is inside an installed package, not a checkout or link. */
|
|
30
|
+
export function isInstalledPackage(srcDir: string): boolean {
|
|
31
|
+
return srcDir.includes(`${sep}node_modules${sep}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Whether this timber runs the plugin-rsc it depends on, rather than the app's. */
|
|
35
|
+
const usesOwnPluginRsc = isInstalledPackage(SRC_DIR);
|
|
36
|
+
|
|
37
|
+
/** plugin-rsc's plugin factory: timber's own copy when installed, the app's otherwise. */
|
|
38
|
+
export function loadPluginRsc(appRoot: string): (typeof import('@vitejs/plugin-rsc'))['default'] {
|
|
39
|
+
const from = usesOwnPluginRsc ? SRC_DIR : appRoot;
|
|
40
|
+
const load = createRequire(join(from, 'package.json'));
|
|
41
|
+
try {
|
|
42
|
+
load.resolve(PLUGIN_RSC);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`timber runs from source or a link here, and loads ${PLUGIN_RSC} from the app: install ${PLUGIN_RSC} in ${appRoot}.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
// Synchronous require() of an ESM package works on Node 22.12+ and
|
|
49
|
+
// returns its namespace.
|
|
50
|
+
const mod: typeof import('@vitejs/plugin-rsc') = load(PLUGIN_RSC);
|
|
51
|
+
return mod.default;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* plugin-rsc lists its vendored Flight runtime in each environment's
|
|
56
|
+
* `optimizeDeps.include` by bare specifier, which Vite resolves from the app's
|
|
57
|
+
* root. An app that does not install plugin-rsc itself cannot resolve it
|
|
58
|
+
* there, so the browser's Flight client would be found only mid-load, and
|
|
59
|
+
* pre-bundled with a full page reload. When timber runs its own copy, each
|
|
60
|
+
* entry names the package it comes through (`@timber-js/app > …`), which Vite
|
|
61
|
+
* resolves from timber.
|
|
62
|
+
*/
|
|
63
|
+
export function timberPluginRscDeps(): Plugin {
|
|
64
|
+
return {
|
|
65
|
+
name: 'timber-plugin-rsc-deps',
|
|
66
|
+
apply: 'serve',
|
|
67
|
+
// After plugin-rsc adds its entries, and after timber-node-flight-builds
|
|
68
|
+
// swaps the server environments' edge builds for Node ones.
|
|
69
|
+
enforce: 'post',
|
|
70
|
+
configEnvironment: {
|
|
71
|
+
order: 'post',
|
|
72
|
+
handler(_name, config) {
|
|
73
|
+
const deps = config.optimizeDeps;
|
|
74
|
+
if (!usesOwnPluginRsc || !deps?.include) return;
|
|
75
|
+
deps.include = deps.include.map((entry) =>
|
|
76
|
+
entry.startsWith(`${PLUGIN_RSC}/`) ? `@timber-js/app > ${entry}` : entry
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -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') &&
|