feat(react): add native React Compiler support - #1419
Conversation
0aaf260 to
89c2017
Compare
ArnaudBarre
left a comment
There was a problem hiding this comment.
I'm wondering if we would not have better stability by always using oxc-transform-react. You could then remove react refresh from the builtin oxc-transform, making it a lot more vendor neutral.
That's a trade off, because it would be a bit slower for people not using the compiler, but in my experience the overhead is not visible in real Vite application (and in build mode without compiler, the builtin transform could still be used)
| compiler ?? (await loadCompiler((message) => this.error(message))) | ||
|
|
||
| const result = await transform(id.split('?')[0]!, code, { | ||
| jsx: 'preserve', |
There was a problem hiding this comment.
Having this plugin doing this transformation with JSX preserve and then the builtin rolldown doing the jsx transformation will make the jsxDev output have wrong line numbers. This breaks various plugin and browser extensions that are using this to jump from the client to the editor in dev mode.
There was a problem hiding this comment.
Re both comments:
oxc-transform-react is intended to provide or react related transforms.
For @vitejs/plugin-react, I want to keep the blast radius minimal so it only uses the react compiler transform from oxc-transform-react.
Having this plugin doing this transformation with JSX preserve and then the builtin rolldown doing the jsx transformation will make the jsxDev output have wrong line numbers.
Is this a bug that I should fix? Does it happen with babel react compiler as well?
Add a
compileroption backed by the optionaloxc-transform-reactpackage.The React Compiler remains a separate package to keep Vite and Rolldown framework-neutral. Framework compilers for React, Svelte, Solid, and others should not increase the size or complexity of the Rolldown binary.
Preliminary benchmarks show that React Compiler execution accounts for more than 80% of the total transform time, outweighing the additional parsing, code generation, and source map costs of running it as a separate transform.
I believe Oxc’s vendored implementation of the Rust React Compiler is now the better-maintained option. It offers better performance, a much smaller binary, correct source maps, and conformance with Babel React Compiler v1. I have validated this conformance against more than 50,000 files from the Oxc ecosystem CI corpus. I continue to fix bugs and am committed to maintaining the React Compiler as a vendored component in Oxc.