Skip to content

Commit

Permalink
fix: ensure logic blocks keep consistent namespacing (#14817)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
trueadm and Rich-Harris authored Jan 6, 2025
1 parent 793f6f3 commit cd1adbc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-onions-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: inherit correct namespace for `<title>` elements
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ export function RegularElement(node, context) {
if (is_svg(node.name)) {
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];
if (ancestor.type === 'RegularElement') {
return ancestor.metadata.svg;
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<svg>
{#if true}
<title>potato</title>
{/if}
</svg>

0 comments on commit cd1adbc

Please sign in to comment.