fix: ensure logic blocks keep consistent namespacing (#14817)

* fix: ensure logic blocks keep consitent namespacing

* lint

* add test

* handle `<title>` ambiguity the same as `<a>`

* update changeset

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/14921/head
Dominic Gannaway 5 days ago committed by GitHub
parent 793f6f3b11
commit cd1adbc4e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: inherit correct namespace for `<title>` elements

@ -90,8 +90,11 @@ export function RegularElement(node, context) {
if (is_svg(node.name)) { if (is_svg(node.name)) {
return true; return true;
} }
if (node.name === 'a') {
for (let i = context.path.length - 1; i >= 0; i--) { if (node.name === 'a' || node.name === 'title') {
let i = context.path.length;
while (i--) {
const ancestor = context.path[i]; const ancestor = context.path[i];
if (ancestor.type === 'RegularElement') { if (ancestor.type === 'RegularElement') {
return ancestor.metadata.svg; return ancestor.metadata.svg;

@ -0,0 +1,11 @@
import { test, ok } from '../../test';
export default test({
html: `<svg><title>potato</title></svg>`,
test({ assert, target }) {
const title = target.querySelector('title');
ok(title);
assert.equal(title.namespaceURI, 'http://www.w3.org/2000/svg');
}
});

@ -0,0 +1,5 @@
<svg>
{#if true}
<title>potato</title>
{/if}
</svg>

After

Width:  |  Height:  |  Size: 56 B

Loading…
Cancel
Save