Repository navigation
Description
Summary
The app's React Compiler transform cache (#3520) works only for vite build. cachedReactCompiler() returns from configResolved before it sets up the cache when config.command !== "build", so the dev server compiles every module again on each start. testReactCompiler(), which apps/app/vitest.config.ts uses since #7603, is a plain Babel plugin with no cache at all. Every app test run, local or CI, compiles every module it loads, and the shared and isolated Vitest projects of one run each compile the same modules again.
On one app test shard, this Babel pass is most of the run: 80-91 s of Vitest transform time out of a 113-131 s run.
Versions and environment
- bb from source at origin/main 2a21dd5.
- Linux (CachyOS, kernel 7.3.4), Node v26.13.1, pnpm 9.15.0, Vite 8.3.6, Vitest 4.1.12.
- Test runs pinned to four CPUs with
taskset -c 16-19, like ablacksmith-4vcpu-ubuntu-2404Linux test runner.
Steps to reproduce
-
pnpm install --frozen-lockfileandpnpm exec turbo run topo //#ensure-native-modules --filter=@bb/app. -
In
apps/app, run the CI shard command twice:LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 BB_CI_TEST_SHARD=3/8 VITEST_MAX_WORKERS=2 \ taskset -c 16-19 ../../node_modules/.bin/vitest run --config vitest.config.ts
-
Read the
Durationline of each run. The second run is as slow as the first, and<git-common-dir>/bb-cache/react-compilergets no test-mode entries.
Expected vs actual
Expected: the second run reuses the compiled output of unchanged modules, as vite build does.
Actual (two runs on origin/main):
Test Files 88 passed (88)
Tests 698 passed | 3 skipped (701)
Duration 130.14s (transform 90.80s, setup 11.18s, import 151.05s, tests 58.14s, environment 26.88s)
Test Files 88 passed (88)
Tests 698 passed | 3 skipped (701)
Duration 112.42s (transform 80.28s, setup 11.07s, import 127.13s, tests 54.93s, environment 21.68s)
With the same cache wrapper applied to the test preset, a warm run of the same shard gives:
Duration 63.66s (transform 14.74s, setup 5.04s, import 46.64s, tests 47.34s, environment 21.55s)
The dev server shows the same cost. A Vite server created from apps/app/vite.dev.config.ts that transforms src/main.tsx, AppLayout.tsx, ThreadDetailView.tsx and TimelineWindowedItems.tsx (about 800 modules with their pre-transformed imports) takes 15.7 s and then 14.1 s on a second server start, with 0 cache hits and 0 misses: the cache is off.
Evidence
- The cache is skipped for every command except build:
bb/apps/app/vite-react-compiler.ts
Lines 112 to 119 in 2a21dd5
plugin.configResolved = async function (this: void, config: ResolvedConfig) { await configResolved.call(this, config); if ( config.command !== "build" || process.env.ENABLE_REACT_COMPILER_TIMINGS === "1" || process.env.BABEL_SHOW_CONFIG_FOR ) return; - The test preset returns an uncached Babel plugin:
bb/apps/app/vite-react-compiler.ts
Lines 241 to 265 in 2a21dd5
export function testReactCompiler() { const preset = reactCompilerPreset(); const pluginSources = resolve( fileURLToPath(new URL("../../plugins/", import.meta.url)), ).replaceAll("\\", "/"); return babel({ presets: [ { ...preset, rolldown: { ...preset.rolldown, filter: { ...preset.rolldown.filter, id: { exclude: new RegExp( `^${pluginSources.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`, ), }, }, applyToEnvironmentHook: () => true, }, }, ], }); } - App tests use that preset:
Line 36 in 2a21dd5
testReactCompiler(), - CI test jobs restore the compiler cache only for
@bb/demo-server:(Windows) andLines 385 to 389 in 2a21dd5
- name: Restore React Compiler cache if: ${{ contains(matrix.filter, '--filter=@bb/demo-server') }} timeout-minutes: 1 continue-on-error: true uses: ./.github/actions/cache-react-compiler (Linux).Lines 667 to 671 in 2a21dd5
- name: Restore React Compiler cache if: ${{ contains(matrix.filter, '--filter=@bb/demo-server') }} timeout-minutes: 1 continue-on-error: true uses: ./.github/actions/cache-react-compiler - Timings come from the Vitest
Durationline and wall time of each run. Two rounds alternated stock and patched runs to spread machine load.
What you ruled out
- A reason to keep the cache build-only. Cache React Compiler transforms across app builds #3520 says "Development and compiler diagnostic modes continue through the original uncached transform" but gives no reason, and the cache key already covers what differs between build, dev and test: Vite mode,
isProduction, Vite environment name, the content of every config file dependency (vite.config.tsandvitest.config.tsdiffer),NODE_ENVandBABEL_*variables, Node version and flags. - Absolute paths in dev or test output.
@vitejs/plugin-reactadds_jsxFileNameafter the Babel pass, so the cached Babel result holds no worktree path, and the existingcontainsWorktreePathcheck still refuses any result that does. - How much CI gains without a restored cache. CI starts each app shard with an empty cache, and in-run reuse between the two Vitest projects gives 113.1 s and 98.5 s against 131.2 s and 113.2 s (18.1 s and 14.7 s less). A warm local cache gives 64.5 s and 62.9 s. CI could get the warm numbers by restoring and saving the cache per app shard, but that adds about 12 x 43 MB of Actions cache per run that tests the app, against the 10 GB quota the Turbo caches also use, and
scripts/cleanup-actions-caches.mjsdoes not delete react-compiler entries. That trade-off is for a maintainer to decide. packages/shared-ui/vitest.config.tshas its own inline Babel preset and does not usetestReactCompiler(). Its suite is small (65 tests), so it is not part of this report.
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 26, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotuiandperflabels.confirmed-repro.b0ddaad731565d7e4de68d824120d802fc78f7d5compile the component in development and test mode but persist zero cache entries. The build control records a warm hit; all four existing cache tests pass.Cache React Compiler output in app tests and the app dev server (get-…
Cache React Compiler output in app tests and the app dev server (get-…