Repository navigation
Conversation
|
Can you update the added playground to use react-router and remove the unit tests? |
Allows `react()` to run next to a plugin that already provides Fast Refresh, such as React Router in framework mode, so that JSX and the React Compiler can still be handled by this plugin. Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
866b804 to
b32c107
Compare
|
Thanks! Done: the playground is now a React Router framework-mode app ( The playground checks that the route module is compiled and only imports React Router's refresh runtime, and that editing it keeps the state. While testing on main I noticed that the compiler's refresh condition from #1516 is inverted: without |
Description
Alternative to #1436, following @ArnaudBarre's suggestion in #1436 (comment): instead of exporting a second plugin, add a
fastRefreshoption toreact()so that it can run next to a plugin that already provides Fast Refresh.The motivating case is React Router framework mode.
reactRouter()runsreact-refresh/babelitself and imports its own refresh runtime into route modules, so withreact({ compiler: true })next to it a route module importsRefreshRuntimetwice and fails withIdentifier 'RefreshRuntime' has already been declared(remix-run/react-router#12870). That leaves no way to use the Rust React Compiler in those apps.Behavior
fastRefresh: falsefolds into the existingskipFastRefreshlogic (the same path as build, production andserver.hmr: false), so the oxcjsx.refreshtransform, the refresh wrapper, the preamble and the compiler'srefreshflag are all skipped. HMR itself stays on.vite:react-compilerisenforce: 'pre', so it sees route modules before React Router rewrites them, and JSX is lowered in the same pass as the compiler, sojsxDEVsource positions match the source file (thejsx: 'preserve'concern from feat: add standalonereactCompilerplugin #1436 does not apply).fastRefreshexisted until 3.x and was removed in 4.0 (feat!: allow to run Babel on non js/ts extensions #122) because the plugin could always enable it on its own. This brings it back for the case where another plugin owns it.Tests
playground/react-routeris a React Router 8.5 framework-mode app (SSR) withreact({ compiler: true, fastRefresh: false })next toreactRouter():jsxDEV, importsRefreshRuntimeonce (from React Router's HMR runtime) and never references/@react-refreshcount is 1becomescount is 1!), so React Router's Fast Refresh works on the compiled outputreactRouter()throws when Vite runs without a config file, and the default test serve usesconfigFile: false, so the playground has a small__tests__/serve.tsthat passes its config file explicitly.Docs: a README section for the option, a pointer from the Rust React Compiler section, and a changelog entry.
🤖 Generated with Claude Code