Visitar URL original
feat(plugin-react): make reactCompilerPreset work with @rolldown/plugin-babel's parallel option by unjica · Pull Request #1549 · vitejs/vite-plugin-react · GitHub
Skip to content

feat(plugin-react): make reactCompilerPreset work with @rolldown/plugin-babel's parallel option - #1549

Merged
sapphi-red merged 3 commits into
vitejs:mainfrom
unjica:fix/react-compiler-preset-parallel
Nov 9, 2026
Merged

sapphi-red merged 3 commits into
vitejs:mainfrom
unjica:fix/react-compiler-preset-parallel

Conversation

@unjica

@unjica unjica commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Description

fixes #1547

reactCompilerPreset() set preset to an inline function. @rolldown/plugin-babel sends the Babel options to worker threads when parallel is set, and a function can't be structured-cloned, so babel({ parallel: true, presets: [reactCompilerPreset()] }) failed with "presets[0]" cannot be sent to a worker thread.

The preset is now a small module, dist/reactCompilerBabelPreset.js (a second tsdown entry). reactCompilerPreset() refers to it by path: preset: [babelPresetPath, options]. The module still resolves babel-plugin-react-compiler with import.meta.resolve from inside @vitejs/plugin-react, the same as before (#1270). The rolldown part (filter, applyToEnvironmentHook, optimizeDeps) stays on the main thread and is unchanged. Without parallel, Babel just loads the preset from the path, so the output is the same.

If the compiler options contain functions (e.g. logger), parallel still can't send them to a worker and @rolldown/plugin-babel reports the same error. Without parallel, these options keep working.

Tests

  • New unit tests in reactCompilerPreset.test.ts: the preset survives structuredClone, and the referenced module adds babel-plugin-react-compiler with the given options. Both fail without this change.
  • pnpm --filter @vitejs/plugin-react test-unit: 58 passed. pnpm lint and pnpm typecheck pass.
  • pnpm test-serve compiler / pnpm test-build compiler pass.
  • I also checked by hand with parallel: true set in playground/compiler and playground/compiler-react-18 (not committed). Before the change, vite build fails with the error from the issue. After it, the build works, the output contains the compiler's memo cache code, and the serve/build e2e tests for both playgrounds pass.

I wrote this with help from an AI assistant. I reviewed the change and ran the tests above myself.

@sapphi-red sapphi-red changed the title fix(plugin-react): make reactCompilerPreset work with @rolldown/plugin-babel's parallel option feat(plugin-react): make reactCompilerPreset work with @rolldown/plugin-babel's parallel option Nov 9, 2026
@sapphi-red
sapphi-red merged commit 8a7d0d4 into vitejs:main Nov 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reactCompilerPreset() can't be used with @rolldown/plugin-babel's parallel option

2 participants