Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jul 6, 2025

Description

@vitejs/plugin-react enables babel transform on all environments when plugins exist and this actually breaks rsc environment. It's possible to workaround but we should have friction-less setup. For now, I'll only add a test as an example and create a separate issue for improve ergonomics.

  • Option 1: functional babel config (looks verbose)
    • this misses auto config of optimizeDeps.include: ["react/compiler-runtime"].
react({
  babel: (_, { ssr }) =>
    ssr ? {} : { plugins: ['babel-plugin-react-compiler'] },
})
  • Option 2: ViteReactPluginApi (works but verbose)
[
  react({ babel: { plugins: ['babel-plugin-react-compiler'] } }),
  {
    name: 'react-babel-override',
    api: {
      reactBabel: (babelConfig, context) => {
        if (context.ssr) {
          babelConfig.plugins = []
        }
      },
    } satisfies ViteReactPluginApi,
  },
]
  • Option 3: works but hacky (type errors or any)
react({ babel: { plugins: ['babel-plugin-react-compiler'] } })
  .map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))
  • Option 4: doesn't work
    • because config hook is not called?
perEnvironmentPlugin(
  'react',
  (e) =>
    e.name === 'client' &&
    react({ babel: { plugins: ['babel-plugin-react-compiler'] } }),
)

@hi-ogawa hi-ogawa force-pushed the 07-05-test_rsc_test_react_compiler branch from bb68bd5 to 3b2489b Compare July 6, 2025 03:05
@hi-ogawa hi-ogawa marked this pull request as ready for review July 6, 2025 07:10
@hi-ogawa hi-ogawa merged commit 2966af5 into vitejs:main Jul 6, 2025
15 checks passed
@hi-ogawa hi-ogawa deleted the 07-05-test_rsc_test_react_compiler branch July 6, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant