Skip to content

Commit a22f29b

Browse files
sapphi-redhi-ogawa
andauthored
fix(react): refreshWrapper was injected twice for class components when using babel plugins and rolldown-vite (#708)
Co-authored-by: Hiroshi Ogawa <[email protected]>
1 parent 28e723b commit a22f29b

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
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+
### Fix `RefreshRuntime` being injected twice for class components on rolldown-vite ([#708](https://github.com/vitejs/vite-plugin-react/pull/708))
6+
57
## 5.0.0 (2025-08-07)
68

79
## 5.0.0-beta.0 (2025-07-28)

packages/plugin-react/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,15 @@ export default function viteReact(opts: Options = {}): Plugin[] {
255255

256256
const isJSX = filepath.endsWith('x')
257257
const useFastRefresh =
258+
!isRolldownVite &&
258259
!skipFastRefresh &&
259260
!ssr &&
260261
(isJSX ||
261262
(opts.jsxRuntime === 'classic'
262263
? importReactRE.test(code)
263264
: code.includes(jsxImportDevRuntime) ||
264265
code.includes(jsxImportRuntime)))
265-
if (useFastRefresh && !isRolldownVite) {
266+
if (useFastRefresh) {
266267
plugins.push([
267268
await loadPlugin('react-refresh/babel'),
268269
{ skipEnvCheck: true },

playground/compiler/__tests__/compiler.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test('should render', async () => {
55
expect(await page.textContent('button')).toMatch('count is 0')
66
expect(await page.click('button'))
77
expect(await page.textContent('button')).toMatch('count is 1')
8+
expect(await page.textContent('.class-component')).toMatch('ClassComponent')
89
})
910

1011
test.runIf(isServe)('should hmr', async () => {

playground/compiler/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from 'react'
22
import './App.css'
3+
import { ClassComponent } from './ClassComponent'
34

45
export function App() {
56
const [count, setCount] = useState(0)
@@ -18,6 +19,7 @@ export function App() {
1819
<p className="read-the-docs">
1920
Click on the Vite and React logos to learn more
2021
</p>
22+
<ClassComponent />
2123
</>
2224
)
2325
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from 'react'
2+
3+
export class ClassComponent extends Component {
4+
public render() {
5+
return <div className="class-component">ClassComponent</div>
6+
}
7+
}

0 commit comments

Comments
 (0)