Skip to content

Commit

Permalink
perf: wrap dynamic import to skip analysis of dynamic imports (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre authored Apr 5, 2023
1 parent 25b652b commit 80f6869
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugin-react/src/fast-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (import.meta.hot) {
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
import.meta.hot.accept((nextExports) => {
if (!nextExports) return;
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-react/src/refreshUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ function predicateOnExport(moduleExports, predicate) {
return true
}

// Hides vite-ignored dynamic import so that Vite can skip analysis if no other
// dynamic import is present (https://github.com/vitejs/vite/pull/12732)
function __hmr_import(module) {
return import(/* @vite-ignore */ module)
}

exports.__hmr_import = __hmr_import
exports.registerExportsForReactRefresh = registerExportsForReactRefresh
exports.validateRefreshBoundaryAndEnqueueUpdate =
validateRefreshBoundaryAndEnqueueUpdate

0 comments on commit 80f6869

Please sign in to comment.