Skip to content

fix(hmr): fix HMR failure for @include markdown files due to cache key mis#5035

Open
yyznm wants to merge 2 commits intovuejs:mainfrom
yyznm:fix-hmr
Open

fix(hmr): fix HMR failure for @include markdown files due to cache key mis#5035
yyznm wants to merge 2 commits intovuejs:mainfrom
yyznm:fix-hmr

Conversation

@yyznm
Copy link
Copy Markdown

@yyznm yyznm commented Nov 18, 2025

Description

Issue where HMR doesn't occur when markdown files included via @include are modified, caused by the route rewriting feature.

This is the minimal reproducible code for the bug.

image

This is the normal behavior

success.mp4

After adding the rewrites configuration, it's found that updates don't work as expected

error.mp4

The root cause of this issue is that the relativePath used to generate the cacheKey is the rewritten path:

// src/node/markdownToVue.ts
file = rewrites.get(file) || file
const relativePath = slash(path.relative(srcDir, file))
const cacheKey = JSON.stringify({ src, ts, relativePath })
if (options.cache !== false) {
  const cached = cache.get(cacheKey)
  if (cached) {
    debug(`[cache hit] ${relativePath}`)
    return cached
  }
}
// ...

However, the only place where clearCache is called with parameters is in plugin.ts, where the relativePath here is the original path before rewriting. This prevents the cache from being cleared properly, resulting in consistent hits to the cached content and thus failing to update to the new content:

// src/node/plugin.ts
importerMap[slash(file)]?.forEach((relativePath) => {
  clearCache(relativePath)
  // ...
})
// ...

My solution is to use the original path when generating the cacheKey.

Linked Issues

Additional Context

@brc-dd brc-dd self-assigned this Nov 18, 2025
@github-actions github-actions bot added the stale label Jan 1, 2026
@brc-dd brc-dd removed the stale label Jan 31, 2026
@brc-dd brc-dd force-pushed the main branch 3 times, most recently from 15a0278 to 09af6c7 Compare March 26, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants