From f3972e1547a837689462deb72a96aac2aa1eec7a Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 22 Feb 2025 20:03:03 +0530 Subject: [PATCH] fix hmr with rewrites --- src/node/markdownToVue.ts | 10 +++++----- src/node/plugin.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index a4f8a20d..b6b00216 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -31,14 +31,14 @@ export interface MarkdownCompileResult { includes: string[] } -export function clearCache(file?: string) { - if (!file) { +export function clearCache(id?: string) { + if (!id) { cache.clear() return } - file = JSON.stringify({ file }).slice(1) - cache.find((_, key) => key.endsWith(file!) && cache.delete(key)) + id = JSON.stringify({ id }).slice(1) + cache.find((_, key) => key.endsWith(id!) && cache.delete(key)) } export async function createMarkdownToVueRenderFn( @@ -83,7 +83,7 @@ export async function createMarkdownToVueRenderFn( file = rewrites.get(file) || file const relativePath = slash(path.relative(srcDir, file)) - const cacheKey = JSON.stringify({ src, file: relativePath }) + const cacheKey = JSON.stringify({ src, file: relativePath, id: fileOrig }) if (isBuild || options.cache !== false) { const cached = cache.get(cacheKey) if (cached) { diff --git a/src/node/plugin.ts b/src/node/plugin.ts index bc377dcb..19ac04a1 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -429,7 +429,7 @@ export async function createVitePressPlugin( return [ ...modules, ...importers.map((id) => { - clearCache(slash(path.relative(srcDir, id))) + clearCache(id) return this.environment.moduleGraph.getModuleById(id) }) ].filter((mod) => mod !== undefined)