Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: claim svg tags in raw mustache tags correctly #8910

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-lobsters-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: claim svg tags in raw mustache tags correctly
12 changes: 5 additions & 7 deletions packages/svelte/src/runtime/internal/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ export function claim_html_tag(nodes, is_svg) {
const start_index = find_comment(nodes, 'HTML_TAG_START', 0);
const end_index = find_comment(nodes, 'HTML_TAG_END', start_index);
if (start_index === end_index) {
return new HtmlTagHydration(undefined, is_svg);
return new HtmlTagHydration(is_svg);
}
init_claim_info(nodes);
const html_tag_nodes = nodes.splice(start_index, end_index - start_index + 1);
Expand All @@ -807,7 +807,7 @@ export function claim_html_tag(nodes, is_svg) {
n.claim_order = nodes.claim_info.total_claimed;
nodes.claim_info.total_claimed += 1;
}
return new HtmlTagHydration(claimed_nodes, is_svg);
return new HtmlTagHydration(is_svg, claimed_nodes);
}

/**
Expand Down Expand Up @@ -1134,13 +1134,11 @@ export class HtmlTag {
}
}

/**
* @extends HtmlTag */
export class HtmlTagHydration extends HtmlTag {
// hydration claimed nodes
/** */
/** @type {Element[]} hydration claimed nodes */
l = undefined;
constructor(claimed_nodes, is_svg = false) {

constructor(is_svg = false, claimed_nodes) {
super(is_svg);
this.e = this.n = null;
this.l = claimed_nodes;
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte/test/hydration/samples/raw-svg/_after.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg>
<circle cx="200" cy="500" r="200"></circle>
</svg>
5 changes: 5 additions & 0 deletions packages/svelte/test/hydration/samples/raw-svg/_before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<svg>
<!-- HTML_TAG_START -->
<circle cx="200" cy="500" r="200"></circle>
<!-- HTML_TAG_END -->
</svg>
14 changes: 14 additions & 0 deletions packages/svelte/test/hydration/samples/raw-svg/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
snapshot(target) {
const svg = target.querySelector('svg');

return {
svg,
circle: svg.querySelector('circle')
};
},
test(assert, _, snapshot) {
assert.instanceOf(snapshot.svg, SVGElement);
assert.instanceOf(snapshot.circle, SVGElement);
}
};
1 change: 1 addition & 0 deletions packages/svelte/test/hydration/samples/raw-svg/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svg>{@html '<circle cx="200" cy="500" r="200"></circle>'}</svg>
2 changes: 0 additions & 2 deletions packages/svelte/test/hydration/samples/raw/_after.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<noscript></noscript>
<p>this is some html</p>
<p>and so is this</p>
<noscript></noscript>
2 changes: 2 additions & 0 deletions packages/svelte/test/hydration/samples/raw/_before.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<!-- HTML_TAG_START -->
<p>this is some html</p>
<p>and so is this</p>
<!-- HTML_TAG_END -->
2 changes: 0 additions & 2 deletions packages/svelte/test/hydration/samples/raw/_config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default {
skip: true, // existing nodes are blown away

props: {
raw: '<p>this is some html</p> <p>and so is this</p>'
},
Expand Down
6 changes: 5 additions & 1 deletion packages/svelte/test/hydration/samples/raw/main.svelte
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{@html raw}
<script>
export let raw;
</script>

{@html raw}
10 changes: 10 additions & 0 deletions packages/svelte/test/runtime/samples/raw-svg/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
html: '',

test({ assert, component, target }) {
component.show = true;
assert.equal(target.innerHTML, '<svg><circle cx="200" cy="500" r="200"></circle></svg>');
assert.instanceOf(target.querySelector('svg'), SVGElement);
assert.instanceOf(target.querySelector('circle'), SVGElement);
}
};
7 changes: 7 additions & 0 deletions packages/svelte/test/runtime/samples/raw-svg/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export let show = false;
</script>

{#if show}
<svg>{@html '<circle cx="200" cy="500" r="200"></circle>'}</svg>
{/if}