From 286360281992c425bf75cb0a18846f65fcdc5ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Thu, 31 Aug 2023 14:43:08 +0200 Subject: [PATCH] fix: better invalidation message when an export is added & fix HMR for export of nullish values (#215) --- packages/plugin-react/src/refreshUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/plugin-react/src/refreshUtils.js b/packages/plugin-react/src/refreshUtils.js index 98b2f3a..0ca2b01 100644 --- a/packages/plugin-react/src/refreshUtils.js +++ b/packages/plugin-react/src/refreshUtils.js @@ -26,9 +26,12 @@ function registerExportsForReactRefresh(filename, moduleExports) { } 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( @@ -36,7 +39,6 @@ function validateRefreshBoundaryAndEnqueueUpdate(prevExports, nextExports) { (key, value) => { hasExports = true if (exports.isLikelyComponentType(value)) return true - if (!prevExports[key]) return false return prevExports[key] === nextExports[key] }, )