Skip to content
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

Wrong clipPath ids - uniqueId not set properly on clip-path style attribute #1244

Open
DamianErtel opened this issue Feb 21, 2023 · 1 comment

Comments

@DamianErtel
Copy link

Hello, we use react-svg and have trouble with clip-paths not being applied correctly, turns out clip-path ids get randomized, but same ids are not updated in clip-path style attribute

elements = svg.querySelectorAll(element + '[id]')
for (let a = 0, elementsLen = elements.length; a < elementsLen; a++) {
currentId = elements[a].id
newId = currentId + '-' + uniqueId()
// All of the properties that can reference this element type.
let referencingElements
Array.prototype.forEach.call(properties, (property: string) => {
// :NOTE: using a substring match attr selector here to deal with IE
// "adding extra quotes in url() attrs".
referencingElements = svg.querySelectorAll(
'[' + property + '*="' + currentId + '"]'
)
for (
let b = 0, referencingElementLen = referencingElements.length;
b < referencingElementLen;
b++
) {
const attrValue: string | null =
referencingElements[b].getAttribute(property)
if (
attrValue &&
!attrValue.match(new RegExp('url\\("?#' + currentId + '"?\\)'))
) {
continue
}
referencingElements[b].setAttribute(
property,
'url(#' + newId + ')'
)
}
})

Screenshot from 2023-02-21 14-41-27

Thanks in advance!

@tanem
Copy link
Owner

tanem commented Feb 24, 2023

Hey, thanks for raising this - yea this is a known issue that I haven't had the chance to fix unfortunately:

There are workarounds mentioned in those issue threads which may or may not fix your use-case. I'll bump the permanent fix up my priority list in the meantime...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants