Skip to content

Commit 25b947e

Browse files
committed
chore: merge main
2 parents db0a431 + bd1487d commit 25b947e

File tree

4 files changed

+362
-481
lines changed

4 files changed

+362
-481
lines changed

packages/plugin-react/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
### Perf: use native refresh wrapper plugin in rolldown-vite ([#881](https://github.com/vitejs/vite-plugin-react/pull/881))
6+
57
## 5.0.3 (2025-09-17)
68

79
### HMR did not work for components imported with queries with rolldown-vite ([#872](https://github.com/vitejs/vite-plugin-react/pull/872))

packages/plugin-react/src/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,36 @@ export default function viteReact(opts: Options = {}): Plugin[] {
362362
const viteRefreshWrapper: Plugin = {
363363
name: 'vite:react:refresh-wrapper',
364364
apply: 'serve',
365+
async applyToEnvironment(env) {
366+
if (env.config.consumer !== 'client' || skipFastRefresh) {
367+
return false
368+
}
369+
370+
let nativePlugin: ((options: any) => Plugin) | undefined
371+
try {
372+
// NOTE: `+` is to bypass lint & typecheck. vite/internal exists for newer rolldown-vite
373+
nativePlugin = (await import('vite' + '/internal'))
374+
.reactRefreshWrapperPlugin
375+
} catch {}
376+
if (
377+
!nativePlugin ||
378+
['7.1.10', '7.1.11', '7.1.12'].includes(vite.version)
379+
) {
380+
// the native plugin in 7.1.10 and 7.1.11 and 7.1.12 does not support dev properly
381+
return true
382+
}
383+
384+
delete viteRefreshWrapper.transform
385+
386+
return nativePlugin({
387+
cwd: process.cwd(),
388+
include: makeIdFiltersToMatchWithQuery(include),
389+
exclude: makeIdFiltersToMatchWithQuery(exclude),
390+
jsxImportSource,
391+
reactRefreshHost: opts.reactRefreshHost ?? '',
392+
}) as unknown as boolean
393+
},
394+
// we can remove this transform hook when we drop support for rolldown-vite 7.1.12 and below
365395
transform: {
366396
filter: {
367397
id: {

0 commit comments

Comments
 (0)