Astro Info
Astro v7.2.2
Vite v8.2.1
Node v24.19.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations none
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
svgoOptimizer() calls SVGO without the path option:
// packages/astro/src/assets/svg/svgo.ts
optimize: (contents) => optimize(contents, config).data,
So SVGO plugins that derive a per-file value from the path cannot work. With prefixIds, every file falls back to SVGO's default prefix, and ids from different SVG files collide once they are inlined on the same page.
In the reproduction, one.svg and two.svg each define a gradient with id="a" — the id SVGO's own cleanupIds plugin emits. Both become prefix__a, so the second definition is unreachable and both squares render red:
<svg viewBox="0 0 24 24"><defs><linearGradient id="prefix__a"><stop offset="0" stop-color="red" /></linearGradient></defs><rect width="24" height="24" fill="url(#prefix__a)" /></svg>
<svg viewBox="0 0 24 24"><defs><linearGradient id="prefix__a"><stop offset="0" stop-color="blue" /></linearGradient></defs><rect width="24" height="24" fill="url(#prefix__a)" /></svg>
parseSvg() in packages/astro/src/assets/svg/utils.ts already has path in scope — it uses it for the CannotOptimizeSvg error message — but does not forward it to svgOptimizer.optimize().
What's the expected result?
Prefixes derived per file. Running SVGO directly with a path produces exactly that:
optimize(contents, { path: 'src/icons/one.svg', plugins: [{ name: 'prefixIds' }] }); // id="one_svg__a"
optimize(contents, { path: 'src/icons/two.svg', plugins: [{ name: 'prefixIds' }] }); // id="two_svg__a"
Link to Minimal Reproducible Example
https://github.com/myakura/test--astro-v7-svgo-prefixids
Built output: https://myakura.github.io/test--astro-v7-svgo-prefixids/
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
svgoOptimizer()calls SVGO without thepathoption:So SVGO plugins that derive a per-file value from the path cannot work. With
prefixIds, every file falls back to SVGO's default prefix, and ids from different SVG files collide once they are inlined on the same page.In the reproduction,
one.svgandtwo.svgeach define a gradient withid="a"— the id SVGO's owncleanupIdsplugin emits. Both becomeprefix__a, so the second definition is unreachable and both squares render red:parseSvg()inpackages/astro/src/assets/svg/utils.tsalready haspathin scope — it uses it for theCannotOptimizeSvgerror message — but does not forward it tosvgOptimizer.optimize().What's the expected result?
Prefixes derived per file. Running SVGO directly with a
pathproduces exactly that:Link to Minimal Reproducible Example
https://github.com/myakura/test--astro-v7-svgo-prefixids
Built output: https://myakura.github.io/test--astro-v7-svgo-prefixids/
Participation