Repository navigation
Description
Investigated and written with the help of an AI coding agent (Claude); reproduced locally.
Describe the bug
When a file that the dev server has transformed is deleted, its module node stays in urlToModuleMap, idToModuleMap and fileToModulesMap (with its transformResult) for the life of the server. onFileDelete only removes the module from its importees' importers.
A re-created path reuses its node, so the graph grows by one node per distinct deleted path: renames, generated files, branch switches. In a long dev session with file-based routing (routes added, renamed, removed) this is a steady leak while the number of live files stays constant.
The repro runs 200 cycles of: create src/gen/mod-<i>.js, import it from src/entry.js, transform both, delete it, wait for the watcher's unlink. At most two files exist at any time.
cycle= 0 liveFiles=1 idToModuleMap=1 urlToModuleMap=1 fileToModulesMap=1 heapUsed=13.4MB
cycle= 100 liveFiles=1 idToModuleMap=101 urlToModuleMap=101 fileToModulesMap=101 heapUsed=14.7MB
cycle= 200 liveFiles=1 idToModuleMap=201 urlToModuleMap=201 fileToModulesMap=201 heapUsed=15.1MB
last deleted file exists on disk: false; still in fileToModulesMap: true; in idToModuleMap: true; in urlToModuleMap: true
Same counts when calling moduleGraph.onFileDelete(file) directly (--direct), and on vite 7.3.7.
Expected: once the deletion is handled, the deleted file's nodes are gone from the maps (sizes stay constant) and their transform results can be collected.
Suggested direction (untested): after the delete HMR update has been computed, also remove the file's modules from fileToModulesMap, urlToModuleMap, idToModuleMap and etagToModuleMap. Related, not duplicates: #14315 (added onFileDelete), #23527 / #23533, #23781.
Reproduction
https://github.com/Sheraff/vite-module-graph-deleted-files
Steps to reproduce
npm install
node --expose-gc repro.mjsNo browser needed.
System Info
System:
OS: Linux 6.12 Debian GNU/Linux 13 (trixie)
CPU: (32) x64 AMD Ryzen 9 9955HX 16-Core Processor
Binaries:
Node: 26.10.0
npm: 12.2.0
npmPackages:
vite: 8.3.5 => 8.3.5Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Activity
fix(moduleGraph): clear transform result on file delete instead of re…
OKAN-SOFTWARE commentedon Oct 29, 2026
Thanks for adding the repeated-cycle regression test! It confirms that the same module node is reused for a single filename.
I noticed one additional edge case:
onFileDelete()setsmod.transformResult = nulldirectly, bypassingupdateModuleTransformResult(), which normally removes the previous ETag frometagToModuleMap.Because the new test assigns a different ETag each cycle, older ETag mappings may accumulate even though
fileToModulesMapremains at size 1.Could we verify that
getModuleByEtag()no longer returns the old ETag after deletion, and clean up that mapping if necessary?Also, the original #23907 reproduction uses distinct filenames across cycles, whereas this test reuses
/test.js. Testing that original scenario would help distinguish reduced source-memory retention from complete graph-map cleanup.I also noticed three SSR HMR failures in the latest Windows CI run. I'm not sure whether they're related, so those may need separate verification.
Thanks for iterating on this!
fix(moduleGraph): clean up stale ETag mapping on file delete