-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Is it possible to change defined ids for every time an svg is rendered? #98
Comments
@jd1378 we'll need a minimal reproduction link on https://stackblitz.com/ to help you out! |
@jd1378 solution to your problem: #94 (comment) more info: svg/svgo#674 (comment) |
@gkatsanos That, definitely is not the solution Anyway i solved this by extracting and injecting my defs to top of body when my svg is being loaded and skiped svgo for it I don't think this is solvable easily (at the level of this library) |
I also encountered this problem when using nuxt-svg-loader (one hell of a problem, it's the same). |
well you can do what I did without any problem:
here is an example: onBeforeMount(() => {
if (!document.getElementById('one-of-your-defs-ids')) {
const fillDef = document.createElementNS(
'http://www.w3.org/2000/svg',
'svg',
);
fillDef.style.position = 'absolute';
fillDef.style.width = '0';
fillDef.style.height = '0';
fillDef.innerHTML =
'<defs><linearGradient id="one-of-your-defs-ids" x1="11.4857" y1="18.2663" x2="9.07356" y2="5.37942" gradientUnits="userSpaceOnUse"><stop stop-color="#f5953d"/><stop offset=".236" stop-color="#eb493a"/><stop offset="1" stop-color="#ffe82f"/></linearGradient></defs>';
document.body.prepend(fillDef);
}
}); I hope this does make it clear for anyone who finds this problem later :) |
right now when loading a svg, the first time its loaded the gradients defined in it works fine
but when you load the same svg for the second time, it no longer renders correctly, as ids clash
I was wondering if we could prefix an incremental number to the svg ids used inside it every time its rendered
The text was updated successfully, but these errors were encountered: