feat: add runtime unique SVG ids - #1028
Open
BarrieLAJ wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
BarrieLAJ
marked this pull request as ready for review
July 10, 2026 10:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
runtimeIdstransform and--runtime-idsCLI flaguseId()while preserving SVGO's file-levelprefixIdsoutputid,url(#id),href,xlinkHref, and inline style referencesclassic-preact, TypeScript,memo, andforwardRefruntimeIds: { importSource: 'custom-runtime/hooks' }Why
SVGO's
prefixIdsprevents collisions between different SVG source files, but every rendered instance of the same generated component still contains the same IDs. When an inline SVG component is mounted more than once, fragment references can resolve to definitions in an earlier instance instead of the instance containing the reference.This option adds uniqueness at render time. It remains disabled by default because applications may rely on predictable generated IDs, as discussed in #322. This also follows the requested direction in #731 without changing existing output unless explicitly enabled.
Behavior
With
runtimeIds: true, generated function components calluseId(), sanitize its value for use in SVG fragment IDs, and prepend it to the IDs already produced by SVGO. Exact fragment references are rewritten to use the same runtime value.Plain hash values are only rewritten for
hrefandxlinkHref; this avoids treating colors such as#fffor external URL fragments as ID references. Custom templates that do not emit the generated function component, including class-component templates, retain their static IDs rather than receiving an invalid hook call.The default hook import is
react. Theclassic-preactruntime usespreact/hooks, and custom runtimes can provide their own import source.Validation
pnpm run buildpnpm test(22 suites, 256 tests, 223 snapshots)memo,forwardRef, colors, external URL fragments, no-ID SVGs, and custom templatesRefs #731
Refs #322