Repository navigation
fix(icon): scope SVG resource IDs per instance - #2416
Conversation
✅ Deploy Preview for stacks-svelte ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 1bf1a66 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for stackoverflow-email ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for stacks ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
asblanco
left a comment
There was a problem hiding this comment.
During review, we (Codex and I?) found that SVG ID scoping only recognized double-quoted attributes. Because Icon accepts arbitrary valid SVG strings, single-quoted or mixed-quote markup could be partially rewritten—for example, id="dot" became instance-scoped while href='#dot' remained unchanged, causing the referenced element not to render.
Commit 1bf1a66
The implementation now supports both quote styles for IDs, href/xlink:href, ARIA references, and quoted or unquoted url() references. The existing double-quote behavior and alternate quoting are covered through parameterized regression tests.
Why
SVGs from Stacks Icons can contain gradients and other resources with fixed IDs. When
Iconrenders the same SVG more than once, duplicate IDs can make a visible copy resolve its paint reference to an earlier hidden copy. This caused the native Microsoft Teams icon to appear blank in the Stack Internal source list.What changed
Iconnow gives each rendered SVG's IDs a stable, instance-specific prefix and updates itsurl(#...), fragmenthref, and ARIA ID references. This applies to any SVG passed toIcon, without icon-specific logic.$props.id().@stackoverflow/stacks-svelte.Review notes
The peer dependency minimum changes from Svelte 5.19 to 5.20.
Iconprops and styling remain the same.Reviewer test plan
Run
npm run test -w packages/stacks-svelte. For a visual check, render two nativeIconServiceMicrosoftTeamsicons, hide the first, and confirm the second retains its colors.