Skip to content

App tests and the app dev server run the React Compiler with no transform cache #8226

Description

@lanjak

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 a blacksmith-4vcpu-ubuntu-2404 Linux test runner.

Steps to reproduce

  1. pnpm install --frozen-lockfile and pnpm exec turbo run topo //#ensure-native-modules --filter=@bb/app.

  2. 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
  3. Read the Duration line of each run. The second run is as slow as the first, and <git-common-dir>/bb-cache/react-compiler gets 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:
    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:
    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:
    testReactCompiler(),
  • CI test jobs restore the compiler cache only for @bb/demo-server:

    bb/.github/workflows/ci.yml

    Lines 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
    (Windows) and

    bb/.github/workflows/ci.yml

    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
    (Linux).
  • Timings come from the Vitest Duration line 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.ts and vitest.config.ts differ), NODE_ENV and BABEL_* variables, Node version and flags.
  • Absolute paths in dev or test output. @vitejs/plugin-react adds _jsxFileName after the Babel pass, so the cached Babel result holds no worktree path, and the existing containsWorktreePath check 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.mjs does not delete react-compiler entries. That trade-off is for a maintainer to decide.
  • packages/shared-ui/vitest.config.ts has its own inline Babel preset and does not use testReactCompiler(). Its suite is small (65 tests), so it is not part of this report.

AGENT GENERATED

Activity

  1. added theissue type on Nov 26, 2026
  2. added
    ui
    confirmed-repro
    on Nov 26, 2026
  3. bb-slop-cop commented on Nov 26, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Medium; applied missing ui and perf labels.
    • Report: Reproduction and root cause — REPRODUCED, high confidence; reproduction label: confirmed-repro.
    • Evidence: Two clean checkouts of trusted main at b0ddaad731565d7e4de68d824120d802fc78f7d5 compile 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.
    • Root cause: The build wrapper skips cache initialization for serve mode, and the test preset constructs an uncached Babel plugin.
    • No new PR: Open linked PR Cache React Compiler output in app tests and the app dev server #8227 already addresses these bypasses; no duplicate fix was opened or linked-PR code executed.
    • Limit: Full-shard timings and projected speedups were not remeasured.

    AGENT GENERATED

  4. added a commit that references this issue on Nov 30, 2026
    1dc151b
  5. added a commit that references this issue on Dec 1, 2026
    0e95a42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproperfui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions