-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite adds spaces after commas in image url within srcset (HTML files) #16323
Comments
Start a new pull request in StackBlitz Codeflow. |
Thanks for providing this use case. It's one I hadn't considered when fixing #16081. Now having spent some time in the srcset parsing code, the solution to your use case is not immediately obvious to me. The parser uses a regex to strip out patterns that contain commas, replaces those patterns with spaces, then adds the pattern back into the string after each srcset has been split by a In my case, I stripped out characters that were in the middle of a word, superseded a There is the srcset package, but it's output doesn't align with what Vite expects. Vite wants:
So, some paths forward are:
|
In my case, the URLs are always with protocol, never relative. But it should be generic; otherwise you will end up with other cases also broken. The |
Describe the bug
Vite appears to add spaces around commas when a comma is present in a
srcset
property. This only occurs in HTML files.If my index.html file contains
Vite outputs
Take note of the space added to the image URL after the comma in the pathname.
/dpr_2, f_auto, fl_progressive, q_auto, w_100/
.To narrow the matching logic, in Cloudinary case, the commas always between slashes.
Reproduction
https://stackblitz.com/edit/vitejs-vite-ruqamh?file=index.html
Steps to reproduce
HTML plugin always breaks it
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.18.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.15.3 - /usr/local/bin/pnpm npmPackages: vite: ^5.2.6 => 5.2.7
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: