feat(config): support next.config reactCompiler option#2678
Draft
314systems wants to merge 3 commits into
Draft
Conversation
Model `reactCompiler` (boolean or { compilationMode, panicThreshold })
in NextConfig/ResolvedNextConfig, and wire it into the auto-registered
@vitejs/plugin-react Babel pipeline.
Mirrors Next.js behavior (packages/next/src/build/get-babel-loader-config.ts):
- the compiler plugin runs on client transforms only (skipped for SSR)
- babel-plugin-react-compiler must be installed in the project (throws
with an install hint otherwise)
- target: '18' is pinned when the installed React major version is 18
- anonymous functions are named in dev
- the compiler plugin runs first in the Babel pipeline
Uses a function-form babel option so the compiler can be toggled by
next.config even though @vitejs/plugin-react is instantiated before
config resolution. With vinext({ react: false }), a warning tells the
user to add the plugin to their own react() setup.
Closes cloudflare#2674
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
314systems
marked this pull request as draft
July 23, 2026 06:40
@vitejs/plugin-react v6 no longer accepts the legacy babel option. Use @rolldown/plugin-babel with a lazy client-only compiler preset instead, while retaining the v5 Babel callback path. Pre-optimize the matching compiler runtime and document the additional v6 dependency requirement. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Author
|
I re-verified this against the installed Fixed in 88cfbf4:
I also ran an isolated real transform with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for the stable Next.js
reactCompilerconfig option:The object form is also supported:
reactCompiler: { compilationMode: "annotation", panicThreshold: "critical_errors" }.Closes #2674
Implementation
Mirrors Next.js behavior from
packages/next/src/build/get-babel-loader-config.ts:babel-plugin-react-compilerand reports a clear install error when missingtarget: "18"when React 18 is installedBoth supported plugin-react generations are handled:
@vitejs/plugin-reactv5 uses its function-formbabeloption@vitejs/plugin-reactv6 uses@rolldown/plugin-babelwith a lazy, client-only preset; this path additionally requires@rolldown/plugin-babelThe v6 path also pre-optimizes
react/compiler-runtimeorreact-compiler-runtime, depending on the detected React target. Withvinext({ react: false }), vinext warns that the compiler must be configured in the user's own React plugin setup.Verification
@rolldown/plugin-babel@0.2.3andbabel-plugin-react-compiler@1.0.0; output containsreact.memo_cache_sentineloptimizeDeps.includeDocumentation
The README configuration table documents the accepted values, dependencies, client-only behavior, and
react: falsecaveat.