Skip to content

Commit 643facd

Browse files
committed
perf(react): use native refresh wrapper plugin in rolldown-vite
1 parent 80df894 commit 643facd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/plugin-react/src/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,34 @@ export default function viteReact(opts: Options = {}): Plugin[] {
355355
const viteRefreshWrapper: Plugin = {
356356
name: 'vite:react:refresh-wrapper',
357357
apply: 'serve',
358+
async applyToEnvironment(env) {
359+
if (env.config.consumer !== 'client' || skipFastRefresh) {
360+
return false
361+
}
362+
363+
let nativePlugin: ((options: any) => Plugin) | undefined
364+
try {
365+
nativePlugin = (await import('vite/internal')).reactRefreshWrapperPlugin
366+
} catch {}
367+
if (
368+
!nativePlugin ||
369+
['7.1.10', '7.1.11', '7.1.12'].includes(vite.version)
370+
) {
371+
// the native plugin in 7.1.10 and 7.1.11 and 7.1.12 does not support dev properly
372+
return true
373+
}
374+
375+
delete viteRefreshWrapper.transform
376+
377+
return nativePlugin({
378+
cwd: process.cwd(),
379+
include: makeIdFiltersToMatchWithQuery(include),
380+
exclude: makeIdFiltersToMatchWithQuery(exclude),
381+
jsxImportSource,
382+
reactRefreshHost: opts.reactRefreshHost ?? '',
383+
}) as unknown as boolean
384+
},
385+
// we can remove this transform hook when we drop support for rolldown-vite 7.1.12 and below
358386
transform: {
359387
filter: {
360388
id: {

0 commit comments

Comments
 (0)