fix(APP-993): Prefix SVG asset ids to prevent url(#id) collisions between inlined icons and illustrations - #723
Conversation
Signed-off-by: Milos Dzepina <milos@aragon.org>
|
🚀 Preview Deployment: View Here |
thekidnamedkd
left a comment
There was a problem hiding this comment.
Previews look the same so that's great, but doesn't 100% prove the solution on the app where the real issue lives with the IDs and render race. I assume you checked that though.
I'm personally less opposed to using packages, but historically we have always retained a high level of scrutiny as a posture before we add anything. We're there vanilla solutions possibly? Or conversely, is there anything more we can do with this package to earn its keep?
@thekidnamedkd yes, of course, I checked it in the app. It was tricky to pin point the issue because it was visible only in the app, but the actual problem was in the ui-kit.
These are all required config packages. |
Description
Human illustrations (e.g. the
SMILE_WINKexpression) render with broken, jagged linework whenever they share a page with common icons (MENU,CLOSE,COPY, nav icons, etc.).Root cause: 57 icon SVGs and several illustration SVGs hardcode short ids like
id="a"for their<clipPath>/<mask>defs. Since SVGR inlines these as raw<svg>markup, all ids share the document's id space — the browser resolvesurl(#a)to the first matching element in the DOM, so e.g.SMILE_WINK's face mask reference silently resolves to a 16×16 icon clip square instead.SVGR's default SVGO config includes the
prefixIdsplugin (namespaces every id per source file, e.g.menu_svg__a), but passing any customsvgoConfigreplaces the default wholesale rather than merging. #715 added a custom config to preserveviewBoxand thereby silently droppedprefixIds, introducing the collision.Changes:
svgo.config.js(single source of truth) that keeps theremoveViewBox: falseoverride from fix: keep SVG viewBox so icons scale instead of clipping #715 and restoresprefixIds.rollup.config.mjs(library build) imports the shared config instead of its inline copy..storybook/main.ts:vite-plugin-svgrruns no SVGO at all by default, so Storybook previews didn't match the published build (and still showed the collision). It now opts into@svgr/plugin-svgowith the same shared config;@svgr/plugin-jsxmust be re-listed since settingpluginsreplaces the default chain.svgo,@svgr/plugin-svgo,@svgr/plugin-jsxdevDependencies (referenced by name as plugin strings, so they must be root-resolvable under pnpm).Verified by building and inspecting
dist/index.es.js: all bundled SVG ids are unique (e.g.menu_svg__a,smile-wink_svg__a), zero duplicates.Type of change
Developer Checklist:
Review Checklist: