injectQuery
incorrectly double-encodes query string parameters
#18244
Labels
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
My code uses
import.meta.url
to read a query string paramter from the URL used to load my module in a browser <script> tag. This works reliably in all environments except that, when HMR is used, the url query string is corrupted when HMR adds a "t=" parameter (presumably to bust the cache).I tracked this down to an issue with the
injectQuery
method.For example, the src given here:
Ends up being read as
import.meta.url
as:http://localhost:5173/src/embed.ts?t=1727723109376&id=66cf6a5a47fe7364e779d3c9&url=https%253A%252F%252Fnewrobotoverlords.com%252Fnotebooklms-a-new-way-to-learn-and-understand%252F
(Note that a
t
parameter has been added, and theurl
parameter has been incorrectly doubly-encoded, or at least has extra "%25" characters added to it.)Reproduction
https://github.com/mykwillis/vite/tree/inject-query-bug
Steps to reproduce
pnpm i
pnpm run test-unit
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: