Skip to content

fix(utils): strip timestamp query when followed by a hash - #23390

Closed
dfedoryshchev wants to merge 1 commit into
vitejs:mainfrom
dfedoryshchev:fix/timestamp-query-hash
Closed

fix(utils): strip timestamp query when followed by a hash#23390
dfedoryshchev wants to merge 1 commit into
vitejs:mainfrom
dfedoryshchev:fix/timestamp-query-hash

Conversation

@dfedoryshchev

Copy link
Copy Markdown
Contributor

removeTimestampQuery() stops stripping the ?t=<13-digit> HMR query when the URL also has a hash fragment, so the timestamp leaks into the module graph.

utils.ts:341's terminator (?:&|$) accepts & or end-of-string but never #. This is a regression from #23364: the previous /\bt=\d{13}&?\b/ matched before a # because of the word boundary.

It is the inverse of injectQuery(), which has a dedicated hash-only branch and emits exactly file?t=<ms>#frag, so the round trip no longer round-trips.

Against a dev server with import iconUrl from './icon.svg#shape', the module-graph URL after an asset update is /icon.svg?t=1787868494725#shape instead of /icon.svg#shape. A new module-graph node is created on every HMR update of that asset, and transformRequest.ts:502's importedMod.url !== moduleUrl check never matches. Fragment URLs are a normal shape here - SVG sprites and #iefix fonts - and the playgrounds use them.

The fix only changes the terminator; \d{13} preceded by ? or & still defines a timestamp. A differential over old and new across query shapes differs on exactly one class, a 13-digit t= followed by a hash: current-t=, my-t=, 12- and 14-digit values, #t=, duplicate timestamps and ?raw&import are all untouched.

Worth noting #22343 was closed as expected behaviour for widening \d{13} to \w+; this does not widen what counts as a timestamp.

Test added to the existing removeTimestampQuery block. The utils suite goes 124 to 125 passing.

cultosagent added a commit to cultosagent/dogma-registry that referenced this pull request Aug 30, 2026
@santusht06

Copy link
Copy Markdown

Tested this locally across all query and hash permutations (?t=...#hash, ?import&t=...#hash, ?t=...&import#hash, mid-query timestamps, etc.).

The lookahead (?=#|$) correctly catches timestamps preceding hash fragments without leaking into the module graph or affecting non-13-digit parameters. All unit tests pass cleanly. LGTM!

@bluwy

bluwy commented Sep 4, 2026

Copy link
Copy Markdown
Member

If this is causing a bug in your app, please open an issue explaining it. What is the usecase for import iconUrl from './icon.svg#shape' etc. Otherwise this seems more of a theoretical fix that we might not hit in practice.

@bluwy bluwy closed this Sep 4, 2026
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.

3 participants