-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
SVG elements not displaying when passed as slot content #7807
Comments
If you can't add <script lang="ts">
/** Ensure all "a" elements inside an SVG node belong to the correct namespace */
function ensureSVGA(node: SVGSVGElement) {
const namespaceSVG = 'http://www.w3.org/2000/svg'
const links = node.querySelectorAll<HTMLLinkElement>('a')
for (const link of links) {
if (link.namespaceURI === namespaceSVG) continue
const a = document.createElementNS(namespaceSVG, 'a')
for (const { name, value } of link.attributes) {
a.setAttribute(name, value)
}
a.append(...link.children)
link.insertAdjacentElement('beforebegin', a)
link.remove()
}
}
</script>
<svg use:ensureSVGA>
<slot />
</svg>
|
I've found a similar problem when loading SVG defs via a Here's the repro: https://svelte.dev/repl/2647caa253d648428dfd96b8d1d6b974?version=3.55.0 If you comment out the main wrapper div, svelte is able to detect the SVG namspace and the gradient shows up. If you wrap the whole thing in a div, it will interpret |
@mhkeller can you |
Yes that it as a viable workaround for now – similar to adding the xmlns attribute inline to the |
related #13793 |
Describe the bug
If you have an SVG component that allows you to pass in child content as a slot like so...
...no content will display if you pass in content wrapped in an anchor tag like so...
However, if you don't use an SVG component and simply write plain SVG, everything displays fine.
It seems that something is breaking when the child content gets sent through the slot.
Reproduction
https://svelte.dev/repl/08270639a2154ea18192cbdf30861da8?version=3.49.0
Logs
No response
System Info
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: