diff --git a/packages/common/refresh-utils.ts b/packages/common/refresh-utils.ts index 559cbaa04..8c0cadc12 100644 --- a/packages/common/refresh-utils.ts +++ b/packages/common/refresh-utils.ts @@ -1,7 +1,7 @@ export const runtimePublicPath = '/@react-refresh' const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/ -const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/ +const refreshContentRE = /\$RefreshReg\$\(/ // NOTE: this is exposed publicly via plugin-react export const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice( diff --git a/packages/plugin-react-oxc/CHANGELOG.md b/packages/plugin-react-oxc/CHANGELOG.md index 7648dec4d..2f93c2517 100644 --- a/packages/plugin-react-oxc/CHANGELOG.md +++ b/packages/plugin-react-oxc/CHANGELOG.md @@ -2,10 +2,14 @@ ## Unreleased -### Add `filter` for rolldown-vite +### Add `filter` for rolldown-vite [#470](https://github.com/vitejs/vite-plugin-react/pull/470) Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite. +### Skip HMR for JSX files with hooks [#480](https://github.com/vitejs/vite-plugin-react/pull/480) + +This removes the HMR warning for hooks with JSX. + ## 0.1.1 (2025-04-10) ## 0.1.0 (2025-04-09) diff --git a/packages/plugin-react-swc/CHANGELOG.md b/packages/plugin-react-swc/CHANGELOG.md index 79ed6f409..aed49abc7 100644 --- a/packages/plugin-react-swc/CHANGELOG.md +++ b/packages/plugin-react-swc/CHANGELOG.md @@ -2,14 +2,18 @@ ## Unreleased -### Add `filter` for rolldown-vite +### Add `filter` for rolldown-vite [#470](https://github.com/vitejs/vite-plugin-react/pull/470) Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite. -### Skip HMR preamble in Vitest browser mode +### Skip HMR preamble in Vitest browser mode [#478](https://github.com/vitejs/vite-plugin-react/pull/478) This was causing annoying `Sourcemap for "/@react-refresh" points to missing source files` and is unnecessary in test mode. +### Skip HMR for JSX files with hooks [#480](https://github.com/vitejs/vite-plugin-react/pull/480) + +This removes the HMR warning for hooks with JSX. + ## 3.9.0 (2025-04-15) ### Make compatible with rolldown-vite diff --git a/packages/plugin-react/CHANGELOG.md b/packages/plugin-react/CHANGELOG.md index ccb6b02c9..52105e6d6 100644 --- a/packages/plugin-react/CHANGELOG.md +++ b/packages/plugin-react/CHANGELOG.md @@ -2,10 +2,14 @@ ## Unreleased -### Add `filter` for rolldown-vite +### Add `filter` for rolldown-vite [#470](https://github.com/vitejs/vite-plugin-react/pull/470) Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite. +### Skip HMR for JSX files with hooks [#480](https://github.com/vitejs/vite-plugin-react/pull/480) + +This removes the HMR warning for hooks with JSX. + ## 4.4.1 (2025-04-19) Fix type issue when using `moduleResolution: "node"` in tsconfig [#462](https://github.com/vitejs/vite-plugin-react/pull/462) diff --git a/playground/hook-with-jsx/__tests__/hook-with-jsx.spec.ts b/playground/hook-with-jsx/__tests__/hook-with-jsx.spec.ts new file mode 100644 index 000000000..570ca8174 --- /dev/null +++ b/playground/hook-with-jsx/__tests__/hook-with-jsx.spec.ts @@ -0,0 +1,27 @@ +import { expect, test } from 'vitest' +import { + editFile, + isServe, + page, + untilBrowserLogAfter, + untilUpdated, +} from '~utils' + +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') +}) + +if (isServe) { + test('Hook with JSX HMR', async () => { + editFile('src/useButtonHook.tsx', (code) => + code.replace('count is {count}', 'count is {count}!'), + ) + await untilBrowserLogAfter( + () => page.textContent('button'), + '[vite] hot updated: /src/App.tsx', + ) + await untilUpdated(() => page.textContent('button'), 'count is 1!') + }) +} diff --git a/playground/hook-with-jsx/__tests__/oxc/hook-with-jsx.spec.ts b/playground/hook-with-jsx/__tests__/oxc/hook-with-jsx.spec.ts new file mode 100644 index 000000000..4696fae50 --- /dev/null +++ b/playground/hook-with-jsx/__tests__/oxc/hook-with-jsx.spec.ts @@ -0,0 +1 @@ +import '../hook-with-jsx.spec' diff --git a/playground/hook-with-jsx/index.html b/playground/hook-with-jsx/index.html new file mode 100644 index 000000000..96ad88a1c --- /dev/null +++ b/playground/hook-with-jsx/index.html @@ -0,0 +1,13 @@ + + +
+ + + +