|
Hi Vite hackers, how does one tie together Vite and Oxc Transform's implementation of React Compiler? The default import { defineConfig } from 'vite'
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
import babel from '@rolldown/plugin-babel'
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
babel({ presets: [reactCompilerPreset()] })
],
})which relies on Babel. But I understand Oxc Transform has, as of two weeks ago, integrated a Rust implementation of React Router that should perform a lot better for large projects. There's an unplugin-oxc that gives this usage example for Vite: // vite.config.ts
import Oxc from 'unplugin-oxc/vite'
export default defineConfig({
plugins: [Oxc()],
})but this causes a double-import of React and the classic error
JSX makes Oxc Transform emit import { t as require_react } from "/node_modules/.vite/deps/react.js";The query string
I don't understand Vite well enough to say why though or how to make it work. The Oxc unplugin just seems to break things out of the box. I'm so confused please help |
Replies: 4 comments 4 replies
|
Use the generated
plugins: [react(), babel({ presets: [reactCompilerPreset()] })]The duplicate React symptom you are seeing is consistent with a separate transform producing a JSX-runtime import that does not go through the same optimized dependency entry as the rest of the React graph. I would remove |
|
Agree with Barry Keep the generated
The Babel only runs for the React Compiler pass, and only on files its code filter matches, because the compiler ships solely as The double-React error is two React runtimes, and your own paste shows why. Vite's dep optimizer serves pre-bundled deps with a So not a config tweak to |
|
You can drop both // vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
react({
babel: {
plugins: [],
},
}),
],
oxc: {
transform: {
reactCompiler: true,
},
},
});That's it. The One thing I learned the hard way: if you have any non-standard React patterns (higher-order components that return render functions, deprecated APIs), Babel Compiler silently transforms them but Oxc may skip or error. I'd add oxc: {
transform: {
reactCompiler: {
strictMode: true,
},
},
},Also make sure you're on |
|
Thanks friends :) i did end up giving the babel plugin the react compiler preset as above but without mentioning the react plugin itself and the angular devtools show optimized components now :) now to remove some of that manual memoization and drastically simplify our code... |
Use the generated
@vitejs/plugin-reactsetup for this today;unplugin-oxcis not a drop-in replacement for the React Compiler path in Vite.@vitejs/plugin-reactv6 already uses Vite/Oxc for the normal JSX + React Refresh transform, but its React Compiler support is explicitly exposed throughreactCompilerPreset()for@rolldown/plugin-babel+babel-plugin-react-compiler:The duplicate React symptom you are seeing is consistent with a separate transform producing a JSX-runtime import that does not go through the same optimized dependency entry as the rest of the React graph. I would remove
unplugin-oxcfor React files and keep …