Skip to content

Commit fd277a2

Browse files
committed
fix: hmr for documents now that _importGlobMap is no longer exposed
1 parent 5013cdd commit fd277a2

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

packages/iles/src/node/plugin/documents.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { resolve } from 'path'
21
import { Plugin, ViteDevServer } from 'vite'
32

43
import glob from 'fast-glob'
@@ -112,12 +111,6 @@ export default function documentsPlugin (config: AppConfig): Plugin {
112111
`
113112
},
114113
async transform (code, id) {
115-
// Ensure Vite keeps track of files with the documents pattern that are added or removed.
116-
if (server && id.startsWith(DOCS_VIRTUAL_ID)) {
117-
(server as any)._importGlobMap.set(id, [resolve(root, modulesById[id].pattern)])
118-
return
119-
}
120-
121114
// Replace each usage of useDocuments with an import of a virtual module.
122115
if (fileCanUseDocuments.test(id) && !definitionRegex.test(code)) {
123116
const paths: [string, string][] = []
@@ -135,13 +128,19 @@ export default function documentsPlugin (config: AppConfig): Plugin {
135128
}
136129
}
137130
},
138-
handleHotUpdate (ctx) {
139-
const file = relative(root, ctx.file)
131+
hotUpdate ({ file, modules }) {
132+
const relFile = relative(root, file)
133+
const extra: typeof modules = []
140134

135+
// Ensure Vite keeps track of files with the documents pattern that are added or removed.
141136
for (const id in modulesById) {
142-
if (modulesById[id].hasDocument(file))
143-
ctx.modules.push(server.moduleGraph.getModuleById(id)!)
137+
if (modulesById[id].hasDocument(relFile)) {
138+
const mod = this.environment.moduleGraph.getModuleById(id)
139+
if (mod) extra.push(mod)
140+
}
144141
}
142+
143+
if (extra.length) return [...modules, ...extra]
145144
},
146145
}
147146
}

0 commit comments

Comments
 (0)