Skip to content

Commit 35221c8

Browse files
authored
fix: claim svg tags in raw mustache tags correctly (#8910)
fixes #8904
1 parent 800f6c0 commit 35221c8

File tree

12 files changed

+57
-12
lines changed

12 files changed

+57
-12
lines changed

.changeset/curvy-lobsters-decide.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: claim svg tags in raw mustache tags correctly

packages/svelte/src/runtime/internal/dom.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ export function claim_html_tag(nodes, is_svg) {
796796
const start_index = find_comment(nodes, 'HTML_TAG_START', 0);
797797
const end_index = find_comment(nodes, 'HTML_TAG_END', start_index);
798798
if (start_index === end_index) {
799-
return new HtmlTagHydration(undefined, is_svg);
799+
return new HtmlTagHydration(is_svg);
800800
}
801801
init_claim_info(nodes);
802802
const html_tag_nodes = nodes.splice(start_index, end_index - start_index + 1);
@@ -807,7 +807,7 @@ export function claim_html_tag(nodes, is_svg) {
807807
n.claim_order = nodes.claim_info.total_claimed;
808808
nodes.claim_info.total_claimed += 1;
809809
}
810-
return new HtmlTagHydration(claimed_nodes, is_svg);
810+
return new HtmlTagHydration(is_svg, claimed_nodes);
811811
}
812812

813813
/**
@@ -1134,13 +1134,11 @@ export class HtmlTag {
11341134
}
11351135
}
11361136

1137-
/**
1138-
* @extends HtmlTag */
11391137
export class HtmlTagHydration extends HtmlTag {
1140-
// hydration claimed nodes
1141-
/** */
1138+
/** @type {Element[]} hydration claimed nodes */
11421139
l = undefined;
1143-
constructor(claimed_nodes, is_svg = false) {
1140+
1141+
constructor(is_svg = false, claimed_nodes) {
11441142
super(is_svg);
11451143
this.e = this.n = null;
11461144
this.l = claimed_nodes;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<svg>
2+
<circle cx="200" cy="500" r="200"></circle>
3+
</svg>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<svg>
2+
<!-- HTML_TAG_START -->
3+
<circle cx="200" cy="500" r="200"></circle>
4+
<!-- HTML_TAG_END -->
5+
</svg>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
snapshot(target) {
3+
const svg = target.querySelector('svg');
4+
5+
return {
6+
svg,
7+
circle: svg.querySelector('circle')
8+
};
9+
},
10+
test(assert, _, snapshot) {
11+
assert.instanceOf(snapshot.svg, SVGElement);
12+
assert.instanceOf(snapshot.circle, SVGElement);
13+
}
14+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svg>{@html '<circle cx="200" cy="500" r="200"></circle>'}</svg>
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
<noscript></noscript>
21
<p>this is some html</p>
32
<p>and so is this</p>
4-
<noscript></noscript>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
<!-- HTML_TAG_START -->
12
<p>this is some html</p>
23
<p>and so is this</p>
4+
<!-- HTML_TAG_END -->

packages/svelte/test/hydration/samples/raw/_config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export default {
2-
skip: true, // existing nodes are blown away
3-
42
props: {
53
raw: '<p>this is some html</p> <p>and so is this</p>'
64
},
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{@html raw}
1+
<script>
2+
export let raw;
3+
</script>
4+
5+
{@html raw}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
html: '',
3+
4+
test({ assert, component, target }) {
5+
component.show = true;
6+
assert.equal(target.innerHTML, '<svg><circle cx="200" cy="500" r="200"></circle></svg>');
7+
assert.instanceOf(target.querySelector('svg'), SVGElement);
8+
assert.instanceOf(target.querySelector('circle'), SVGElement);
9+
}
10+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
export let show = false;
3+
</script>
4+
5+
{#if show}
6+
<svg>{@html '<circle cx="200" cy="500" r="200"></circle>'}</svg>
7+
{/if}

0 commit comments

Comments
 (0)