Skip to content

fix(removeUnknownsAndDefaults): keep attributes referenced by attribute selectors#2226

Open
mahirhir wants to merge 1 commit into
svg:mainfrom
mahirhir:keep-selector-referenced-attrs
Open

fix(removeUnknownsAndDefaults): keep attributes referenced by attribute selectors#2226
mahirhir wants to merge 1 commit into
svg:mainfrom
mahirhir:keep-selector-referenced-attrs

Conversation

@mahirhir

Copy link
Copy Markdown

#2144 made this plugin keep an attribute when its value equals the default and it's referenced by an attribute selector such as [preserveAspectRatio]. That guard only landed in the "default value" branch.

The same loop deletes attributes in two other branches: unknown attributes, and attributes that redundantly override an inherited value. Neither one looks at the stylesheet, so both still remove attributes that a selector relies on.

For example, running only this plugin on:

<svg xmlns="http://www.w3.org/2000/svg">
  <style>rect[fill] { stroke: red; }</style>
  <g fill="blue">
    <rect fill="blue" width="10" height="10"/>
  </g>
</svg>

rect's fill="blue" repeats the parent value, so the uselessOverrides branch drops it, rect[fill] stops matching, and the rect loses its stroke. A custom attribute used as a styling hook ([state]) runs into the same thing through the unknown-attribute branch.

This applies the existing includesAttrSelector check to all three branches instead of just one. Added a test fixture covering the two cases that weren't handled.

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.

1 participant