Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit 2e78d52

Browse files
committed
fix: better invalidation message when an export is added & fix HMR for export of nullish values
1 parent 684c3c0 commit 2e78d52

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Disable Fast Refresh based on `config.server.hmr === false` instead of `process.env.TEST`
66
- Warn when plugin is in WebContainers (see [#118](https://github.com/vitejs/vite-plugin-react-swc/issues/118))
7+
- Better invalidation message when an export is added & fix HMR for export of nullish values ([#143](https://github.com/vitejs/vite-plugin-react-swc/issues/143))
78

89
## 3.3.2
910

playground/hmr/__tests__/hmr.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test("HMR invalidate", async ({ page }) => {
4646
'React!";\nexport const useless = 3;',
4747
]);
4848
await waitForLogs(
49-
"[vite] invalidate /src/TitleWithExport.tsx: Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react-swc#consistent-components-exports",
49+
"[vite] invalidate /src/TitleWithExport.tsx: Could not Fast Refresh (new export)",
5050
"[vite] hot updated: /src/App.tsx",
5151
);
5252

src/refresh-runtime.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,19 @@ export function validateRefreshBoundaryAndEnqueueUpdate(
587587
prevExports,
588588
nextExports,
589589
) {
590-
if (!predicateOnExport(prevExports, (key) => !!nextExports[key])) {
590+
if (!predicateOnExport(prevExports, (key) => key in nextExports)) {
591591
return "Could not Fast Refresh (export removed)";
592592
}
593+
if (!predicateOnExport(nextExports, (key) => key in prevExports)) {
594+
return "Could not Fast Refresh (new export)";
595+
}
593596

594597
let hasExports = false;
595598
const allExportsAreComponentsOrUnchanged = predicateOnExport(
596599
nextExports,
597600
(key, value) => {
598601
hasExports = true;
599602
if (isLikelyComponentType(value)) return true;
600-
if (!prevExports[key]) return false;
601603
return prevExports[key] === nextExports[key];
602604
},
603605
);

0 commit comments

Comments
 (0)