fix: hmr not working for watched files in path loaders

follow up on #4525
pull/4600/head
Divyansh Singh 7 months ago
parent 9f54714e7d
commit e271695d71

@ -307,7 +307,8 @@ export async function createVitePressPlugin(
if (url?.endsWith('.html')) { if (url?.endsWith('.html')) {
res.statusCode = 200 res.statusCode = 200
res.setHeader('Content-Type', 'text/html') res.setHeader('Content-Type', 'text/html')
let html = `<!DOCTYPE html> let html = `\
<!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title></title>

@ -187,10 +187,17 @@ export const dynamicRoutesPlugin = async (
// Also check if the file matches any custom watch patterns. // Also check if the file matches any custom watch patterns.
let watchedFileChanged = false let watchedFileChanged = false
for (const [, route] of routeModuleCache) { for (const [file, route] of routeModuleCache) {
if (route.watch && isMatch(normalizedFile, route.watch)) { if (route.watch && isMatch(normalizedFile, route.watch)) {
route.routes = undefined route.routes = undefined
watchedFileChanged = true watchedFileChanged = true
for (const id of moduleGraph.delete(file)) {
const mod = this.environment.moduleGraph.getModuleById(id)
if (mod) {
modules.push(mod)
}
}
} }
} }

@ -150,7 +150,7 @@ export const staticDataPlugin: Plugin = {
const loader = idToLoaderModulesMap[id] const loader = idToLoaderModulesMap[id]
if (loader && loader.watch && isMatch(normalizedFile, loader.watch)) { if (loader && loader.watch && isMatch(normalizedFile, loader.watch)) {
const mod = this.environment.moduleGraph.getModuleById(id) const mod = this.environment.moduleGraph.getModuleById(id)
if (mod && !modules.includes(mod)) { if (mod) {
modules.push(mod) modules.push(mod)
} }
} }

Loading…
Cancel
Save