-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
bug: svg "sprites" are broken when using svgo #1896
Comments
This issue is caused by either cleanupIds or removeHiddenElems |
What is the original SVG's purpose? It seems to be to define things, as it renders nothing. How is it being used? |
It is used as a Sprite sheet (instead of requesting a lot of icons on a page, we can just request this file once and pick the item out of it with It is for all icons here: Example on how it is used in a React component:
|
You can basically render the elements inside |
As SVGO caters to standalone SVGs, this isn't a bug, but SVGO working as intended - removing unused definitions. However you can customize SVGO to disable that behavior, by turning off removeHiddenElems and cleanupIds, as these both have the sole purpose to optimize defs within the SVG. |
Thank you, this was indeed the case - had to disable both
|
Describe the bug
We used to format our svg sprites with
npx svgo --pretty -f ./public/sprites
. This was working previously, but now returns empty svgs. I couldn't make out the version when this started happening. Issue seems to be coming from<defs>
?To Reproduce
/regions.svg
npx svgo --pretty regions.svg
results in:
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" aria-hidden="true" overflow="hidden" style="position:absolute;width:0;height:0"/>
Running without
--pretty
has the same resultsDesktop (please complete the following information):
Additional context
There's multiple svgs just like this in /public/sprites
The text was updated successfully, but these errors were encountered: