Skip to content

Commit e271695

Browse files
committed
fix: hmr not working for watched files in path loaders
follow up on #4525
1 parent 9f54714 commit e271695

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/node/plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ export async function createVitePressPlugin(
307307
if (url?.endsWith('.html')) {
308308
res.statusCode = 200
309309
res.setHeader('Content-Type', 'text/html')
310-
let html = `<!DOCTYPE html>
310+
let html = `\
311+
<!DOCTYPE html>
311312
<html>
312313
<head>
313314
<title></title>

src/node/plugins/dynamicRoutesPlugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,17 @@ export const dynamicRoutesPlugin = async (
187187

188188
// Also check if the file matches any custom watch patterns.
189189
let watchedFileChanged = false
190-
for (const [, route] of routeModuleCache) {
190+
for (const [file, route] of routeModuleCache) {
191191
if (route.watch && isMatch(normalizedFile, route.watch)) {
192192
route.routes = undefined
193193
watchedFileChanged = true
194+
195+
for (const id of moduleGraph.delete(file)) {
196+
const mod = this.environment.moduleGraph.getModuleById(id)
197+
if (mod) {
198+
modules.push(mod)
199+
}
200+
}
194201
}
195202
}
196203

src/node/plugins/staticDataPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const staticDataPlugin: Plugin = {
150150
const loader = idToLoaderModulesMap[id]
151151
if (loader && loader.watch && isMatch(normalizedFile, loader.watch)) {
152152
const mod = this.environment.moduleGraph.getModuleById(id)
153-
if (mod && !modules.includes(mod)) {
153+
if (mod) {
154154
modules.push(mod)
155155
}
156156
}

0 commit comments

Comments
 (0)