Skip to content

Commit

Permalink
fix: invalidate import globs upon new/removed files (fix #3499) (#3500)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout authored May 21, 2021
1 parent 06b9935 commit b31604e
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 b31604e

Please sign in to comment.