Open hugoattal opened 10 months ago
Start a new pull request in StackBlitz Codeflow.
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:
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. So we could have the same logic of inlining in the dev mode, but that might break reactivity on SVGs...
If we default to inline, the problem can be undetected before build. If we default to file, build will be good by default, but this will change the behavior of what vite already does.
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'))) &&
cf https://github.com/hugoattal/vite/commit/0e9b6361c210293b743acc24da098cee2da84db2
Wdyt?
TIL data URLs now disallowed in <use>
.
There's a PR that adds a option to exclude some files to be inlined: #15366
I guess that PR will work for this case as well.
TIL data URLs now disallowed in
<use>
.
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 😅...
There's a PR that adds a option to exclude some files to be inlined: https://github.com/vitejs/vite/pull/15366
I think the ?file
suffix would be a bit more practical, but I'm okay with the solution of this PR 🙂
Hello! Also faced the issue recently. Is there any news on the topic?
Also faced this problem recently.
assetsInlineLimit: 0
fix the issue but... well you would not inline anything.
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