Skip to content

Commit

Permalink
fix(better-define): cycle imports on HMR
Browse files Browse the repository at this point in the history
closes #227
  • Loading branch information
sxzz committed Jan 24, 2023
1 parent 60093ab commit 0ec95df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-kids-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-macros/better-define': patch
---

fix cycle imports on HMR
4 changes: 4 additions & 0 deletions packages/better-define/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ export default createUnplugin<Options | undefined, false>(
},

handleHotUpdate({ file, server, modules }) {
const cache = new Map<string, Set<ModuleNode>>()
function getAffectedModules(file: string): Set<ModuleNode> {
if (cache.has(file)) return cache.get(file)!

if (!referencedFiles.has(file)) return new Set([])
const modules = new Set<ModuleNode>([])
cache.set(file, modules)
for (const importer of referencedFiles.get(file)!) {
const mods = server.moduleGraph.getModulesByFile(importer)
if (mods) mods.forEach((m) => modules.add(m))
Expand Down

0 comments on commit 0ec95df

Please sign in to comment.