fix: ensure svg namespace for `<a>` elements is correct (#14756)

* fix: ensure svg namespace persists from parent of if blocks

* better fix

* better fix

* address feedback
pull/14770/head
Dominic Gannaway 1 week ago committed by GitHub
parent bfa0b34663
commit 8705d44c64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure svg namespace for `<a>` elements is correct

@ -86,7 +86,23 @@ export function RegularElement(node, context) {
(attribute) => attribute.type === 'SpreadAttribute' (attribute) => attribute.type === 'SpreadAttribute'
); );
node.metadata.svg = is_svg(node.name); const is_svg_element = () => {
if (is_svg(node.name)) {
return true;
}
if (node.name === 'a') {
for (let i = context.path.length - 1; i >= 0; i--) {
const ancestor = context.path[i];
if (ancestor.type === 'RegularElement') {
return ancestor.metadata.svg;
}
}
}
return false;
};
node.metadata.svg = is_svg_element();
node.metadata.mathml = is_mathml(node.name); node.metadata.mathml = is_mathml(node.name);
if (is_custom_element_node(node) && node.attributes.length > 0) { if (is_custom_element_node(node) && node.attributes.length > 0) {

@ -0,0 +1,11 @@
import { test, ok } from '../../test';
export default test({
html: `<svg><a href="/docs"><text class="small" x="20" y="40"></text></a></svg>`,
test({ assert, target }) {
const a = target.querySelector('a');
ok(a);
assert.equal(a.namespaceURI, 'http://www.w3.org/2000/svg');
}
});

@ -0,0 +1,7 @@
<svg>
{#if true}
<a href="/docs">
<text x="20" y="40" class="small">{name}</text>
</a>
{/if}
</svg>

After

Width:  |  Height:  |  Size: 109 B

Loading…
Cancel
Save