Repository navigation
break(svgr): prefix inline SVG ids to avoid clashes between SVGs (AI-assisted) - #12690
Merged
Merged
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Size Change: +13.2 kB (+0.11%) Total Size: 12.5 MB 📦 View Changed
ℹ️ View Unchanged
|
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
⚡️ Lighthouse report for the deploy preview of this PR
|
|
Size Change: +13.2 kB (+0.11%) Total Size: 12.5 MB 📦 View Changed
ℹ️ View Unchanged
|
…assisted) SVGO minifies the ids of each SVG file independently, so inline SVGs of the same page end up sharing ids like "a" and render with each other's gradients, masks or clip paths. The default SVGO config now also enables the `prefixIds` plugin, with a short hash of the site-relative SVG file path as prefix. Class names are not prefixed. Breaking change: ids inside inline SVGs are now prefixed. Only SVGs that contain a `<style>` or `<script>` element kept their original ids before. The plugin docs explain how to restore the v3 SVGO config. Fix #8297 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… references (AI-assisted) Co-Authored-By: Claude Opus 5.5 <[email protected]>
slorber
force-pushed
the
claude/svgr-prefix-ids
branch
from
October 16, 2026 09:56
0658a76 to
a1e0382
Compare
Merged
1 of 3 tasks
2 of 3 tasks
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.
Breaking Changes
@docusaurus/plugin-svgrnow prefixes the ids inside inline SVGs (SVG files imported as React components). The default SVGO config adds theprefixIdsplugin, using a short hash of the site-relative SVG file path as prefix:<linearGradient id="a">becomes<linearGradient id="svg-3f2a1c-a">. References to the ids (url(#a),href="#a", ids in the SVG<style>) are updated too. Class names are not prefixed.Who is affected: sites whose CSS code, JavaScript code (
document.getElementById()…) or URL fragments target an id inside an inline SVG that contains a<style>or<script>element. Other SVGs are not affected in practice: SVGO already removed their unreferenced ids and minified the referenced ones in v3, so their original ids were never in the HTML.Sites that already provide their own
svgrConfig.svgoConfig, or usesvgoConfig: undefinedwith ansvgo.config.jsfile, are not affected: their SVGO config replaces the default one.How to migrate: target SVG elements with class names or attribute selectors instead of ids, for example:
How to restore the v3 behavior: provide the Docusaurus v3 SVGO config, which is the v4 default config without the
prefixIdsplugin:Use the
@docusaurus/plugin-svgrplugin options (samesvgrConfigobject) if you don't use the classic preset. With this config, several SVGs inlined in the same page can clash again.Pre-flight checklist
Motivation
Fix #8297, v4 TODO in
svgrLoader.ts, discussed in #10679.SVGO's
cleanupIdsplugin minifies the ids of each SVG file independently. Most SVGs using gradients, masks or clip paths end up using the same ids (a,b,c…). When several SVGs are inlined in the same page, these ids clash, and SVGs render with the gradients or masks of another SVG. This is a long-standing pain point (#8297, #8191, #10205, #10211, #10679), and users had to find and copy custom SVGO configs to fix it.SVGR enables
prefixIdsby default, but Docusaurus lost it because it provides its ownsvgoConfig. Our own website already usedprefixIdsthrough a customsvgo.config.js(removed in #12689).Implementation choices:
gradient.svgfiles in different folders to cover this.prefixClassNames: false): users may target the class names inside SVGs with their own CSS (attribute selectors and class names are the recommended way to style inline SVGs in our docs).svgo@^3. Its v4 defaults (noremoveTitle/removeViewBox) match the overrides we already use.I also documented the default SVGR config in the plugin docs: the
svgrConfigoption is shallow-merged over it, so providingsvgoConfigreplaces the default SVGO config. The docs only describe the current behavior; the v3 → v4 migration instructions above are meant for the future v4 migration guide.(AI-assisted)
Test Plan
<img>reference rendering, and the 139 ids of the page are unique (they were 53 unique ids out of 139 before).Test links
Deploy preview: https://deploy-preview-12690--docusaurus-2.netlify.app/
Related issues/PRs
🤖 Generated with Claude Code