Skip to content

Keep root <svg> attributes such as fill and stroke on rendered icons - #20

Merged
evoactivity merged 5 commits into
mainfrom
fix/19-root-presentation-attrs
Oct 26, 2026
Merged

evoactivity merged 5 commits into
mainfrom
fix/19-root-presentation-attrs

Conversation

@evoactivity

Copy link
Copy Markdown
Contributor

Fixes #19.

Attributes on the root <svg> of a source file, such as fill, stroke and stroke-width, were dropped. Icons whose children rely on inheriting them rendered wrongly. Heroicons outline icons, for example, rendered as solid shapes.

What changed

  • A new rootAttributes option lists the root attributes to keep. The default is the inheritable presentation attributes: fill, fill-opacity, fill-rule, stroke, stroke-width, stroke-linecap, stroke-linejoin, stroke-miterlimit, stroke-dasharray, stroke-dashoffset, stroke-opacity, clip-rule, opacity and color. A list you give replaces the default, and an empty list turns the feature off.
  • Each runtime sets these attributes on the <svg> it renders. This applies in sprite, inline and dev modes, for all 7 targets.
  • Attributes passed to the component, and CSS rules on the rendered <svg>, override the copied values.
  • With currentColor on, the root fill and stroke are replaced the same way as on the children.
  • The Ember runtime sets the attributes with a modifier, because the Ember build precompiles template() calls and needs a fixed template string.

Why this is breaking

Any icon with presentation attributes on its root <svg> now renders the way the source file does, and that can differ from how it rendered before. For example, an SVG with stroke="black" on its root now shows that stroke on its shapes. To keep the old rendering, set rootAttributes: [].

Tests

  • Unit tests cover findRootAttrs, the option and codegen.
  • A Rollup integration test checks the full build with SVGO.
  • E2E tests in each Vite test project check that the attributes are on the rendered <svg>, that inline children inherit them, and that caller attributes or CSS override them.
  • The darwin screenshots are updated. The linux screenshots need the update-baselines workflow run on this branch.

🤖 Generated with Claude Code

evoactivity and others added 3 commits October 26, 2026 11:20
Attributes such as fill, stroke and stroke-width on the root <svg> are
lost when svg-jar builds a symbol or inline markup. These tests describe
the fix: a configurable rootAttributes list, read from the root <svg> by
findRootAttrs and passed by codegen to createSvg and createSvgInline, so
each runtime sets them on the rendered <svg>.

The e2e tests add a Heroicons outline icon to each Vite test project and
check that the attributes take effect and that a caller attribute or CSS
rule overrides them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Attributes such as fill, stroke and stroke-width on the root <svg> of a
source file were dropped, so icons that rely on children inheriting them,
like Heroicons outline icons, rendered as solid shapes.

The load hook now reads the attributes named in the new rootAttributes
option from the root <svg>, and codegen passes them to createSvg and
createSvgInline. Each runtime sets them on the <svg> it renders, before
any attributes from the caller, so caller attributes and CSS rules still
override them. The Ember runtime uses a modifier because the Ember build
precompiles template() calls and needs a fixed template string.

The integration tests now compare parsed attribute objects, because
SVGO sorts attributes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The project only had a linux baseline, so the first local e2e run on
macOS failed while Playwright created it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@evoactivity
evoactivity merged commit 472e02b into main Oct 26, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Root <svg> presentation attributes (fill, stroke, stroke-width) are dropped from symbols

1 participant