Skip to content

Commit

Permalink
fix: invalidate import globs upon new/removed files (fix vitejs#3499) (
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout authored and fi3ework committed May 22, 2021
1 parent fcfd1fb commit 2e34433
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/playground/glob-import/__tests__/glob-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ if (!isBuild) {
JSON.stringify(
{
'/dir/a.js': {},
...allResult
...allResult,
'/dir/index.js': {
modules: {
'./a.js': {},
...allResult['/dir/index.js'].modules
}
}
},
null,
2
Expand All @@ -75,7 +81,15 @@ if (!isBuild) {
'/dir/a.js': {
msg: 'a'
},
...allResult
...allResult,
'/dir/index.js': {
modules: {
'./a.js': {
msg: 'a'
},
...allResult['/dir/index.js'].modules
}
}
},
null,
2
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ export async function handleFileAddUnlink(
const relative = path.relative(base, file)
if (match(relative, pattern)) {
modules.push(module)
// We use `onFileChange` to invalidate `module.file` so that subsequent `ssrLoadModule()`
// calls get fresh glob import results with(out) the newly added(/removed) `file`.
server.moduleGraph.onFileChange(module.file!)
}
}
}
Expand Down

0 comments on commit 2e34433

Please sign in to comment.