Version dev modules with a per-module counter that moves only when content changes
Maintainers usually reply within 1 day
@MuhammadAhmad67889 is already working on this.
Since Nov 19, 2026.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript, vite
Research direction
Start by tracing the Vite 8.3.5 code paths named in the issue: handleHMRUpdate, updateModules, EnvironmentModuleGraph.invalidateModule, import analysis, the client's importUpdatedModule, transformRequest, and loadAndTransform. Map how module versions and invalidation counters flow through those paths, then check the HMR tests covering no-op saves, reverts, accepting boundaries, and invalidation races. Done means the counter design meets the listed behaviors without missed updates or redundant runs.
Written by the indexing model from the issue text.
Description
Description
During dev, Vite versions an updated module with the clock. Every change event sets lastHMRTimestamp to the current time on the changed module and on its importers, and import analysis injects it as ?t=<ms>. No step compares the new content to the current content. Four costs follow from that:
- A save that changes nothing still re-runs code. Writing the same bytes (a formatter that changes nothing, an editor's save-all, a branch switch that restores a file) issues new URLs, new transforms and a fresh evaluation of the module and every importer up to its boundary.
- Importers above an accepting boundary get the new stamp too, though the browser keeps their instances. Their next import is a new URL, so a lazily imported importer evaluates twice (#23942).
- The race guards depend on the clock.
transformRequestandloadAndTransformcompare millisecond timestamps, which tie within one millisecond (#19804) and miss an invalidation recorded in the other timestamp field (#23941). - Each version is a new id to anything keyed by id. Plugins and frameworks see the timestamped id and often cache by it or embed it in virtual module ids, so a long dev session adds an entry per save, no-op saves included.
Suggested solution
Give each module node a small integer version, used in the URL as ?hmr=<n>, and move it only when the module's served code can actually differ:
- Bump on a real change only. On a change event, hash the file's bytes and compare with the hash stored for that file. Equal bytes end the update: no invalidation, no message to the client.
- Compare with the current content only, never with older versions. A revert (A, then B, then A again) still bumps, because A differs from the current B. A content-addressed URL would be wrong here: the browser's module map never evicts a URL, so the reverted module would come back as the old, already evaluated instance and miss the update.
- Bump only the modules the browser re-runs: the changed module and its importers up to and including the accepting boundary. Importers above the boundary have their transform invalidated (their code embeds the boundary's new URL) but keep their version, so their URL stays the one the browser holds.
- Guard races with a second per-module counter, bumped on every invalidation (file change,
reloadModule(),invalidateModule()), in place oflastInvalidationTimestamp. A request records the counter when it starts and stores its result only if the counter has not moved. Counters do not tie, and every invalidation path moves the same field.
Measured costs on an M2 Pro, Node 24:
- Reading and hashing a changed file at watch time takes about 60 µs for 10 kB and 130 µs for 100 kB, nearly all of it the read. sha256 of the buffer alone is 4 µs at 10 kB.
- The stored hash adds about 125 bytes per watched file.
- A small-integer version is smaller than the two heap-number timestamps it replaces on each node.
A model of seven saves of one module (A, A, B, A, B, B, C, A), counting evaluations in the browser:
| Versioning | Evaluations | Real changes | Missed updates | Redundant runs | Module map entries |
|---|---|---|---|---|---|
Clock ?t=<ms> (today) |
7 | 5 | 0 | 2 | 8 |
| Content hash in the URL | 3 | 5 | 3 | 1 | 4 |
| Counter bumped on content change | 5 | 5 | 0 | 0 | 6 |
Alternative
- Reuse
?v=. Not possible:DEP_VERSION_RE(/[?&](v=[\w.-]+)\b/) marks such URLs as optimized deps, which are servedmax-age=31536000,immutable. - Keep
?t=with a small counter. Not possible as is:timestampRE(/(\?|&)t=\d{13}(?:&|$)/) only strips 13-digit values, so a counter int=would leak into module ids. - Skip unchanged saves only, keep the clock. That removes the no-op re-runs, but leaves the re-stamp above the boundary, the clock-based race guards and the growing id space.
Additional context
Code references (8.3.5): the timestamp is assigned in handleHMRUpdate and updateModules, propagated in EnvironmentModuleGraph.invalidateModule, injected by import analysis and by the client's importUpdatedModule, and compared in transformRequest and loadAndTransform. #6035 describes the importer chain receiving the timestamp.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- Dominant language
- TypeScript
- Stars
- 84k
- Forks
- 9.2k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 103
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vitejs/vite
-
Export the default server.fs.deny patternsPossibly taken @rvitaliy claimed this 19 days ago. Openpending triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vitejs/vite#24015 · 1 reaction ·
Maintainers usually reply within 1 day
-
normalizePath removes the Windows device namespace prefixPossibly taken @sep2 claimed this 23 days ago. Openp2-edge-case
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vitejs/vite#23986 · 1 comment ·
Maintainers usually reply within 1 day
-
Build fails with EISDIR when a `<link>` href is only a query stringPossibly taken @bhumin18 claimed this 32 days ago. Openfeat: html p2-edge-case
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
vitejs/vite#23807 · 1 comment ·
Maintainers usually reply within 1 day
-
Add a "copy error" button to the dev server error overlayPossibly taken @RajX-dev claimed this 131 days ago. Openp2-to-be-discussed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vitejs/vite#22980 · 1 reaction ·
Maintainers usually reply within 1 day
-
Disconnect HMR WebSocket on pagehide for BFCache compatibilityMay be free again A pull request for this issue was closed without being merged. Openpending triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
vitejs/vite#22361 · 5 comments · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
knaw-huc/textannoviz#742 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
cloudflare/realtimekit-ui#219 ·
Maintainers usually reply within 1 day
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaksPossibly taken @argszero claimed this today. Openarea/tui platform/wsl status/repro-simulated type/bug version/v2
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
anomalyco/opencode#66773 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
mermaid-js/mermaid-v13#1370 ·
Maintainers usually reply within 1 day