fix: hmr working only once for markdown files

closes #4909
pull/4910/head
Divyansh Singh 1 month ago
parent 8abbe298d5
commit 8d8a5ac281

@ -4,6 +4,7 @@ import {
mergeConfig, mergeConfig,
normalizePath, normalizePath,
searchForWorkspaceRoot, searchForWorkspaceRoot,
type EnvironmentModuleNode,
type Plugin, type Plugin,
type ResolvedConfig, type ResolvedConfig,
type Rollup, type Rollup,
@ -400,19 +401,22 @@ export async function createVitePressPlugin(
const hmrFix: Plugin = { const hmrFix: Plugin = {
name: 'vitepress:hmr-fix', name: 'vitepress:hmr-fix',
async hotUpdate({ file, modules }) { async hotUpdate({ file, modules: existingMods }) {
if (this.environment.name !== 'client') return if (this.environment.name !== 'client') return
const modules: EnvironmentModuleNode[] = []
const importers = [...(importerMap[slash(file)] || [])] if (file.endsWith('.md')) {
if (importers.length > 0) { const mod = this.environment.moduleGraph.getModuleById(file)
return [ mod && modules.push(mod)
...modules,
...importers.map((id) => {
clearCache(id)
return this.environment.moduleGraph.getModuleById(id)
})
].filter((mod) => mod !== undefined)
} }
importerMap[slash(file)]?.forEach((importer) => {
clearCache(importer)
const mod = this.environment.moduleGraph.getModuleById(importer)
mod && modules.push(mod)
})
return modules.length ? [...existingMods, ...modules] : undefined
} }
} }

Loading…
Cancel
Save