Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better invalidation message when an export is added & fix HMR for export of nullish values #143

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading