-
-
Notifications
You must be signed in to change notification settings - Fork 67
Consider running iconify's replaceIDs
function on SVGs
#127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How are you referencing these ids if they're random? You can also use the plugins: [
'cleanupIds',
{
name: 'prefixIds',
params: {
prefix() {
this.counter = this.counter || 0;
return `id-${this.counter++}`;
}
}
}
] I'm going to consider adding an option to enable this. I think it could cause unwanted issues for people looking to directly reference the ids. |
I've set up another demo to explain what I mean: https://github.com/charlie-hadden/astro-icon-reproduction/tree/replace-ids If you give it a try then please use pnpm as there's a patch for astro-icon there to pass the svgo options through (as per #129). If you run that project then you'll see there are two SVGs displayed. In I then have another branch which has a pnpm patch to add the This issue was also quite confusing for me when I first ran across it, because at that point I didn't have any custom svgo config at all - the default preset is enough to trigger the issue with these SVGs. Hopefully that explains what I mean a little better but let me know if there's anything you'd like me to expand on. |
I was also bitten by this issue, and it was a pain to understand what was going on since the SVGs are fine on their own, and I didn't activate svgo manually, so had no idea that it could be the culprit. In the end I ended up fixing this with the code below on icon({
svgoOptions: {
plugins: [
{ name: 'preset-default' },
{
name: 'prefixIds',
params: {
prefix: () => generateUniqueId(),
},
},
],
},
}), |
+1 to doing something here. I was just trying to update a project to v1 and noticed this as a regression. With The |
Hi again and sorry for the wave of issues here. This is another one for v1.
Some of the SVGs I'm using reference elements by ID. This works fine when there's a single SVG on the page, but with multiples it's possible for the IDs to collide causing issues with things such as masks. Iconify provides a function which resolves this for me: https://iconify.design/docs/icon-components/svg-framework/replace-ids.html
I currently have a pnpm patch which adds the import and replaces
astro-icon/packages/core/components/Icon.astro
Line 104 in e66e3ad
with
This is enough to fix the issue for me by generating unique IDs for each. I'd be happy to submit a PR for this unless it's more convenient for somebody else to do so, but before I do, is there any preference on what prefix to use? Using
replaceIDs
as above generates ID's like so:Thanks!
The text was updated successfully, but these errors were encountered: