diff --git a/packages/plugin-react/CHANGELOG.md b/packages/plugin-react/CHANGELOG.md index c1dc40979..131a1fc9e 100644 --- a/packages/plugin-react/CHANGELOG.md +++ b/packages/plugin-react/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +### Fix `RefreshRuntime` being injected twice for class components on rolldown-vite ([#708](https://github.com/vitejs/vite-plugin-react/pull/708)) + ## 5.0.0 (2025-08-07) ## 5.0.0-beta.0 (2025-07-28) diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 87d00b167..3a4cdbc51 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -255,6 +255,7 @@ export default function viteReact(opts: Options = {}): Plugin[] { const isJSX = filepath.endsWith('x') const useFastRefresh = + !isRolldownVite && !skipFastRefresh && !ssr && (isJSX || @@ -262,7 +263,7 @@ export default function viteReact(opts: Options = {}): Plugin[] { ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime))) - if (useFastRefresh && !isRolldownVite) { + if (useFastRefresh) { plugins.push([ await loadPlugin('react-refresh/babel'), { skipEnvCheck: true }, diff --git a/playground/compiler/__tests__/compiler.spec.ts b/playground/compiler/__tests__/compiler.spec.ts index 742b6f37a..0889e0bd4 100644 --- a/playground/compiler/__tests__/compiler.spec.ts +++ b/playground/compiler/__tests__/compiler.spec.ts @@ -5,6 +5,7 @@ test('should render', async () => { expect(await page.textContent('button')).toMatch('count is 0') expect(await page.click('button')) expect(await page.textContent('button')).toMatch('count is 1') + expect(await page.textContent('.class-component')).toMatch('ClassComponent') }) test.runIf(isServe)('should hmr', async () => { diff --git a/playground/compiler/src/App.tsx b/playground/compiler/src/App.tsx index 3cdc1d623..07f8d0add 100644 --- a/playground/compiler/src/App.tsx +++ b/playground/compiler/src/App.tsx @@ -1,5 +1,6 @@ import { useState } from 'react' import './App.css' +import { ClassComponent } from './ClassComponent' export function App() { const [count, setCount] = useState(0) @@ -18,6 +19,7 @@ export function App() {
Click on the Vite and React logos to learn more
+