Skip to content

Commit cd1adbc

Browse files
trueadmRich-Harris
andauthored
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 <[email protected]>
1 parent 793f6f3 commit cd1adbc

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

.changeset/real-onions-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: inherit correct namespace for `<title>` elements

packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ export function RegularElement(node, context) {
9090
if (is_svg(node.name)) {
9191
return true;
9292
}
93-
if (node.name === 'a') {
94-
for (let i = context.path.length - 1; i >= 0; i--) {
93+
94+
if (node.name === 'a' || node.name === 'title') {
95+
let i = context.path.length;
96+
97+
while (i--) {
9598
const ancestor = context.path[i];
9699
if (ancestor.type === 'RegularElement') {
97100
return ancestor.metadata.svg;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, ok } from '../../test';
2+
3+
export default test({
4+
html: `<svg><title>potato</title></svg>`,
5+
test({ assert, target }) {
6+
const title = target.querySelector('title');
7+
ok(title);
8+
9+
assert.equal(title.namespaceURI, 'http://www.w3.org/2000/svg');
10+
}
11+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<svg>
2+
{#if true}
3+
<title>potato</title>
4+
{/if}
5+
</svg>

0 commit comments

Comments
 (0)