Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/plugin-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Disable refresh for non-jsx with compiler enabled (fix [#1478](https://github.com/vitejs/vite-plugin-react/issues/1478)) ([#1485](https://github.com/vitejs/vite-plugin-react/pull/1485))

When the compiler was enabled, TS files could trigger fast refresh which would cause runtime errors. The logic now follows what the builtin oxc plugin in Vite does.

## 6.1.1 (2026-08-28)

### Add `compiler.logDiagnostics` option
Expand Down
15 changes: 14 additions & 1 deletion packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ function createReactCompilerPlugin(
reactCompilerOptions.target === '17' || reactCompilerOptions.target === '18'
? 'react-compiler-runtime'
: 'react/compiler-runtime'
const jsxImportSource = reactOptions.jsxImportSource ?? 'react'
const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`
const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`

const loadCompiler = async (
onError: (message: string) => never,
Expand Down Expand Up @@ -348,7 +351,17 @@ function createReactCompilerPlugin(
},
},
async handler(code, id) {
// Follow what the builtin oxc plugin does: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/oxc.ts#L250-L267
const [filepath] = id.split('?')
const isJSX = filepath.endsWith('x')
const isClient = this.environment?.config.consumer !== 'server'
const refreshEnabled =
isClient &&
isFastRefreshEnabled() &&
(isJSX ||
code.includes(jsxImportRuntime) ||
code.includes(jsxImportDevRuntime))

const shouldCompile =
isClient &&
(reactCompilerOptions.compilationMode === 'annotation'
Expand All @@ -363,7 +376,7 @@ function createReactCompilerPlugin(
runtime: reactOptions.jsxRuntime,
development: jsxDevelopment,
importSource: reactOptions.jsxImportSource,
refresh: isClient && isFastRefreshEnabled(),
refresh: refreshEnabled,
},
reactCompiler: shouldCompile ? reactCompilerOptions : false,
sourcemap: this.environment
Expand Down
Loading