Skip to content

Commit

Permalink
fix: better invalidation message when an export is added & fix HMR fo…
Browse files Browse the repository at this point in the history
…r export of nullish values (#143)
  • Loading branch information
ArnaudBarre authored Aug 31, 2023
1 parent 684c3c0 commit 733010c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Disable Fast Refresh based on `config.server.hmr === false` instead of `process.env.TEST`
- Warn when plugin is in WebContainers (see [#118](https://github.com/vitejs/vite-plugin-react-swc/issues/118))
- 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))

## 3.3.2

Expand Down
2 changes: 1 addition & 1 deletion playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test("HMR invalidate", async ({ page }) => {
'React!";\nexport const useless = 3;',
]);
await waitForLogs(
"[vite] invalidate /src/TitleWithExport.tsx: Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react-swc#consistent-components-exports",
"[vite] invalidate /src/TitleWithExport.tsx: Could not Fast Refresh (new export)",
"[vite] hot updated: /src/App.tsx",
);

Expand Down
6 changes: 4 additions & 2 deletions src/refresh-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,17 +587,19 @@ export function validateRefreshBoundaryAndEnqueueUpdate(
prevExports,
nextExports,
) {
if (!predicateOnExport(prevExports, (key) => !!nextExports[key])) {
if (!predicateOnExport(prevExports, (key) => key in nextExports)) {
return "Could not Fast Refresh (export removed)";
}
if (!predicateOnExport(nextExports, (key) => key in prevExports)) {
return "Could not Fast Refresh (new export)";
}

let hasExports = false;
const allExportsAreComponentsOrUnchanged = predicateOnExport(
nextExports,
(key, value) => {
hasExports = true;
if (isLikelyComponentType(value)) return true;
if (!prevExports[key]) return false;
return prevExports[key] === nextExports[key];
},
);
Expand Down

0 comments on commit 733010c

Please sign in to comment.