diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 7ee6535ea..87d00b167 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -245,6 +245,14 @@ export default function viteReact(opts: Options = {}): Plugin[] { })() const plugins = [...babelOptions.plugins] + // remove react-compiler plugin on non client environment + if (ssr) { + const reactCompilerPlugin = getReactCompilerPlugin(plugins) + if (reactCompilerPlugin) { + plugins.splice(plugins.indexOf(reactCompilerPlugin), 1) + } + } + const isJSX = filepath.endsWith('x') const useFastRefresh = !skipFastRefresh && diff --git a/packages/plugin-rsc/e2e/react-compiler.test.ts b/packages/plugin-rsc/e2e/react-compiler.test.ts index de8e9c52e..2c36e24b5 100644 --- a/packages/plugin-rsc/e2e/react-compiler.test.ts +++ b/packages/plugin-rsc/e2e/react-compiler.test.ts @@ -22,12 +22,7 @@ test.describe(() => { const overrideConfig = defineConfig({ plugins: [ - react({ - babel: { plugins: ['babel-plugin-react-compiler'] }, - }).map((p) => ({ - ...p, - applyToEnvironment: (e) => e.name === 'client', - })), + react({ babel: { plugins: ['babel-plugin-react-compiler'] } }), rsc(), ], })