Skip to content

Compare React Compiler output, not Vite's import analysis, in cache tests - #8420

Merged
ymichael merged 1 commit into
mainfrom
bb/fix-react-compiler-cache-test-flake-on-windows-thr_e7adxibbz9
Nov 30, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/fix-react-compiler-cache-test-flake-on-windows-thr_e7adxibbz9

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The two cross-server React Compiler cache tests (from #8227) compared the full server.transformRequest result, which includes the rewrites from Vite's import analysis. That step resolves a module's imports in parallel inside Promise.all (vite/dist/node/chunks/node.js, interopNamedImports). For each CJS-interop dependency it calls str.appendLeft(fileStart, hoistedAssignments) when that dependency's resolution finishes. On Windows the react/compiler-runtime and react/jsx-dev-runtime resolutions sometimes finish in a different order, so the prepended lines come out swapped. The cached compiler output is the same in both runs. From the failed Windows (app-4) job:

- ...component.tsx");const _jsxDEV = __vite__cjsImport1_react_jsxDevRuntime["jsxDEV"];const _c = __vite__cjsImport0_react_compilerRuntime["c"];import ...
+ ...component.tsx");const _c = __vite__cjsImport0_react_compilerRuntime["c"];const _jsxDEV = __vite__cjsImport1_react_jsxDevRuntime["jsxDEV"];import ...

The two lines just swap places. Their import indices stay the same, so this is ordering in Vite, not a cache or path-separator problem.

What changed

apps/app/src/test/react-compiler-cache.test.ts: the cross-server tests add a pre probe plugin right after the compiler plugin. The probe records the code the compiler (or the cache) returned for the input module, and the tests compare that code instead of Vite's final output. The probe matches on normalizePath(input) so it also works with Windows ids. Production code is unchanged.

How you verified

  • pnpm exec turbo run test --filter=@bb/app -- src/test/react-compiler-cache.test.ts: 6/6 pass.
  • To check the probe still catches cache bugs, I temporarily made cache hits return code + ';'. Both cross-server tests failed, and passed again once the change was reverted.
  • pnpm exec turbo run typecheck --filter=@bb/app passes.

AGENT GENERATED

🤖 Generated with Claude Code

…ests

Vite resolves a module's imports in parallel and prepends each CJS interop
assignment as its resolution finishes, so the final transformRequest code can
order those lines differently between two servers. The cross-server cache
tests now capture the compiler plugin's own output with a pre-transform probe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit bd578d3 into main Nov 30, 2026
80 of 99 checks passed
@ymichael
ymichael deleted the bb/fix-react-compiler-cache-test-flake-on-windows-thr_e7adxibbz9 branch November 30, 2026 23:32
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…ests (get-bb#8420)

## Human comments

## What was wrong

The two cross-server React Compiler cache tests (from get-bb#8227) compared
the full `server.transformRequest` result, which includes the rewrites
from Vite's import analysis. That step resolves a module's imports in
parallel inside `Promise.all` (`vite/dist/node/chunks/node.js`,
`interopNamedImports`). For each CJS-interop dependency it calls
`str.appendLeft(fileStart, hoistedAssignments)` when that dependency's
resolution finishes. On Windows the `react/compiler-runtime` and
`react/jsx-dev-runtime` resolutions sometimes finish in a different
order, so the prepended lines come out swapped. The cached compiler
output is the same in both runs. From the failed Windows (app-4) job:

```
- ...component.tsx");const _jsxDEV = __vite__cjsImport1_react_jsxDevRuntime["jsxDEV"];const _c = __vite__cjsImport0_react_compilerRuntime["c"];import ...
+ ...component.tsx");const _c = __vite__cjsImport0_react_compilerRuntime["c"];const _jsxDEV = __vite__cjsImport1_react_jsxDevRuntime["jsxDEV"];import ...
```

The two lines just swap places. Their import indices stay the same, so
this is ordering in Vite, not a cache or path-separator problem.

## What changed

`apps/app/src/test/react-compiler-cache.test.ts`: the cross-server tests
add a `pre` probe plugin right after the compiler plugin. The probe
records the code the compiler (or the cache) returned for the input
module, and the tests compare that code instead of Vite's final output.
The probe matches on `normalizePath(input)` so it also works with
Windows ids. Production code is unchanged.

## How you verified

- `pnpm exec turbo run test --filter=@bb/app --
src/test/react-compiler-cache.test.ts`: 6/6 pass.
- To check the probe still catches cache bugs, I temporarily made cache
hits return `code + ';'`. Both cross-server tests failed, and passed
again once the change was reverted.
- `pnpm exec turbo run typecheck --filter=@bb/app` passes.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant