Describe the bug
The removeDimensions option removes width and height attributes from nested <svg> elements, even when it is unsafe to do so.
To Reproduce
Take this example SVG:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">
<path fill="pink" d="M0 0h10v10H0Z"/>
<svg x="1" y="1" width="8" height="8" viewBox="0 0 33 33">
<path fill="red" d="M1 16a1 1 0 0 0 31 1 1 1 0 0 0-31-1"/>
</svg>
</svg>
One can use SVGOMG to quickly see that toggling the "Prefer viewBox to width/height" shows a significant change in the rendered SVG.
Expected behavior
It is expected that this option only affects the outermost <svg> element, since the width and height on nested <svg> elements are used to correctly size and position the nested SVG.
Screenshots
Original SVG (rendered as PNG):
Compressed SVG (as PNG):
Desktop (please complete the following information):
- SVGO 4.0.1
- Node v22.22.1
- OS: MacOS Tahoe 26.2
Describe the bug
The
removeDimensionsoption removeswidthandheightattributes from nested<svg>elements, even when it is unsafe to do so.To Reproduce
Take this example SVG:
One can use SVGOMG to quickly see that toggling the "Prefer viewBox to width/height" shows a significant change in the rendered SVG.
Expected behavior
It is expected that this option only affects the outermost
<svg>element, since thewidthandheighton nested<svg>elements are used to correctly size and position the nested SVG.Screenshots
Original SVG (rendered as PNG):
Compressed SVG (as PNG):
Desktop (please complete the following information):