-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Major browsers (Chrome, Firefox...) just removed data URLs in SVG elements, resulting in a difference betweend dev and prod #15453
Comments
|
For anyone stumbling upon this issue, here's an easy way to solve it in the meantime: Before: import './style.css';
import viteLogo from '/src/vite.svg';
document.querySelector('#app').innerHTML = `
<div>
<svg width="256px" height="256px">
<use href="${viteLogo}#logo"></use>
</svg>
</div>
`; After: import './style.css';
import viteLogo from '/src/vite.svg?raw';
document.querySelector('#app').innerHTML = `
<div>
<div style="display:none;">${viteLogo}</div>
<svg width="256px" height="256px">
<use href="#logo"></use>
</svg>
</div>
`; |
I'm willing to tackle the issue, but I'm not exactly sure how to proceed... There's already this logic: vite/packages/vite/src/node/plugins/asset.ts Lines 350 to 351 in 56ae92c
But fragments can be added after importing the file (just like in my example) I think there can be two solutions:
The second solution does not fix the problem of difference between dev and prod, though. If we default to inline, the problem can be undetected before build. Here's how this could be solved: // Don't inline SVG with fragments, as they are meant to be reused
(!(file.endsWith('.svg') && (id.includes('#') || id.endsWith('?file'))) && Wdyt? |
TIL data URLs now disallowed in |
You can't imagine the headache to find out why my icons were not displayed anymore, a browser update was at the veeeeery bottom of my list 😅...
I think the |
Hello! Also faced the issue recently. Is there any news on the topic? |
Also faced this problem recently. |
Describe the bug
Article: https://developer.chrome.com/blog/migrate-way-from-data-urls-in-svg-use?hl=en
Chrome status: https://chromestatus.com/feature/5128825141198848
Vite seems to inline SVGs when building a project.
But data URLs in SVG don't work anymore (cf article).
So there's a difference between dev (when there's no inlining, everything work) and prod (when it's inlined, it does not display anything)
Reproduction
https://stackblitz.com/edit/vitejs-vite-meuqwh?file=main.js&terminal=dev
Steps to reproduce
pnpm run dev
The rendered SVG element looks like this:
=> Works as intended
pnpm run build && pnpx serve dist
The rendered SVG element looks like this:
=> Does not work
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: