Skip to content

Commit 2f62dc0

Browse files
authored
fix(react): always skip react-compiler on non client envrionment (#689)
1 parent 5057858 commit 2f62dc0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/plugin-react/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ export default function viteReact(opts: Options = {}): Plugin[] {
245245
})()
246246
const plugins = [...babelOptions.plugins]
247247

248+
// remove react-compiler plugin on non client environment
249+
if (ssr) {
250+
const reactCompilerPlugin = getReactCompilerPlugin(plugins)
251+
if (reactCompilerPlugin) {
252+
plugins.splice(plugins.indexOf(reactCompilerPlugin), 1)
253+
}
254+
}
255+
248256
const isJSX = filepath.endsWith('x')
249257
const useFastRefresh =
250258
!skipFastRefresh &&

packages/plugin-rsc/e2e/react-compiler.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ test.describe(() => {
2222
2323
const overrideConfig = defineConfig({
2424
plugins: [
25-
react({
26-
babel: { plugins: ['babel-plugin-react-compiler'] },
27-
}).map((p) => ({
28-
...p,
29-
applyToEnvironment: (e) => e.name === 'client',
30-
})),
25+
react({ babel: { plugins: ['babel-plugin-react-compiler'] } }),
3126
rsc(),
3227
],
3328
})

0 commit comments

Comments
 (0)