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
2 changes: 2 additions & 0 deletions packages/plugin-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

### Perf: use native refresh wrapper plugin in rolldown-vite ([#881](https://github.com/vitejs/vite-plugin-react/pull/881))

## 5.0.3 (2025-09-17)

### HMR did not work for components imported with queries with rolldown-vite ([#872](https://github.com/vitejs/vite-plugin-react/pull/872))
Expand Down
30 changes: 30 additions & 0 deletions packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,36 @@ export default function viteReact(opts: Options = {}): Plugin[] {
const viteRefreshWrapper: Plugin = {
name: 'vite:react:refresh-wrapper',
apply: 'serve',
async applyToEnvironment(env) {
if (env.config.consumer !== 'client' || skipFastRefresh) {
return false
}

let nativePlugin: ((options: any) => Plugin) | undefined
try {
// NOTE: `+` is to bypass lint & typecheck. vite/internal exists for newer rolldown-vite
nativePlugin = (await import('vite' + '/internal'))
.reactRefreshWrapperPlugin
} catch {}
if (
!nativePlugin ||
['7.1.10', '7.1.11', '7.1.12'].includes(vite.version)
) {
// the native plugin in 7.1.10 and 7.1.11 and 7.1.12 does not support dev properly
return true
}

delete viteRefreshWrapper.transform

return nativePlugin({
cwd: process.cwd(),
include: makeIdFiltersToMatchWithQuery(include),
exclude: makeIdFiltersToMatchWithQuery(exclude),
jsxImportSource,
reactRefreshHost: opts.reactRefreshHost ?? '',
}) as unknown as boolean
},
// we can remove this transform hook when we drop support for rolldown-vite 7.1.12 and below
transform: {
filter: {
id: {
Expand Down
Loading
Loading