Skip to content

fix(removeDimensions): only remove dimensions from the top-most <svg>#2225

Open
abhu85 wants to merge 1 commit into
svg:mainfrom
abhu85:fix/remove-dimensions-nested-svg
Open

fix(removeDimensions): only remove dimensions from the top-most <svg>#2225
abhu85 wants to merge 1 commit into
svg:mainfrom
abhu85:fix/remove-dimensions-nested-svg

Conversation

@abhu85

@abhu85 abhu85 commented Jun 22, 2026

Copy link
Copy Markdown

Problem

Fixes #2217.

removeDimensions strips width/height from every <svg> element, including nested ones:

<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" 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="..."/>
  </svg>
</svg>

Today the nested <svg> loses width="8" height="8", which changes how it is sized and positioned — the rendered output is visibly different. The plugin docs say it should only affect "the top-most <svg> element", so this is a behavior/doc mismatch.

Fix

Gate the visitor on parentNode.type === 'root' so only the outermost <svg> is touched — the same root-detection other plugins already use (removeOffCanvasPaths, reusePaths, addAttributesToSVGElement; removeViewBox uses the inverse to handle nested <svg>). Nested <svg> dimensions are now preserved.

Test plan

  • Added fixture test/plugins/removeDimensions.06.svg.txt: outer <svg> drops width/height, nested <svg> keeps them.
  • New fixture fails on main (nested dims stripped) and passes with the fix.
  • Existing removeDimensions.01.05 unchanged; full plugin fixture suite 370 passing.
  • eslint + prettier --check clean.

removeDimensions deleted width/height from every <svg>, including nested
ones, even though the docs state it affects only the top-most <svg>.
Nested <svg> elements rely on width/height for sizing and positioning,
so stripping them changes the rendered output. Gate the visitor on
`parentNode.type === 'root'`, matching how other root-only plugins
(removeOffCanvasPaths, reusePaths) detect the outermost <svg>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

removeDimensions removes width and height from nested SVG elements

1 participant