Skip to content

Commit 11225ab

Browse files
committed
{@html} moves for slot on update
1 parent 1c39f60 commit 11225ab

File tree

9 files changed

+110
-3
lines changed

9 files changed

+110
-3
lines changed

src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class RawMustacheTagWrapper extends Tag {
3939
}
4040

4141
else {
42-
const needs_anchor = in_head || (this.next && !this.next.is_dom_node());
42+
const needs_anchor = in_head || (this.next && !this.next.is_dom_node()) || !this.parent || !this.parent.is_dom_node();
4343

4444
const html_tag = block.get_unique_name('html_tag');
4545
const html_anchor = needs_anchor && block.get_unique_name('html_anchor');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let content;
3+
</script>
4+
5+
{@html content}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export default {
2+
html: `
3+
<button>Switch</button>
4+
<p>Another first line</p>
5+
<p>This line should be last.</p>
6+
`,
7+
async test({ assert, target, window }) {
8+
const btn = target.querySelector("button");
9+
const clickEvent = new window.MouseEvent("click");
10+
11+
await btn.dispatchEvent(clickEvent);
12+
13+
assert.htmlEqual(
14+
target.innerHTML,
15+
`
16+
<button>Switch</button>
17+
<p>First line</p>
18+
<p>This line should be last.</p>
19+
`
20+
);
21+
22+
await btn.dispatchEvent(clickEvent);
23+
24+
assert.htmlEqual(
25+
target.innerHTML,
26+
`
27+
<button>Switch</button>
28+
<p>Another first line</p>
29+
<p>This line should be last.</p>
30+
`
31+
);
32+
},
33+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
import RawMustache from './RawMustache.svelte';
3+
4+
let content1 = `<p>First line</p>`;
5+
let content2 = `<p>Another first line</p>`
6+
7+
let show = false;
8+
$: content = show ? content1 : content2;
9+
</script>
10+
11+
<button on:click={() => show = !show}>
12+
Switch
13+
</button>
14+
15+
<RawMustache {content} />
16+
17+
<p>This line should be last.</p>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<slot />
2+
<p>This line should be last.</p>
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
export default {
2-
html: `<p>x<span>baz</span></p>`
2+
html: `
3+
<button>Switch</button>
4+
<p>Another first line</p>
5+
<p>This line should be last.</p>
6+
`,
7+
async test({ assert, target, window }) {
8+
const btn = target.querySelector("button");
9+
const clickEvent = new window.MouseEvent("click");
10+
11+
await btn.dispatchEvent(clickEvent);
12+
13+
assert.htmlEqual(
14+
target.innerHTML,
15+
`
16+
<button>Switch</button>
17+
<p>First line</p>
18+
<p>This line should be last.</p>
19+
`
20+
);
21+
22+
await btn.dispatchEvent(clickEvent);
23+
24+
assert.htmlEqual(
25+
target.innerHTML,
26+
`
27+
<button>Switch</button>
28+
<p>Another first line</p>
29+
<p>This line should be last.</p>
30+
`
31+
);
32+
},
333
};
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
<p>{@html 'x'}<span>baz</span></p>
1+
<script>
2+
import Component from './Component.svelte';
3+
4+
let content1 = `<p>First line</p>`;
5+
let content2 = `<p>Another first line</p>`
6+
7+
let show = false;
8+
$: content = show ? content1 : content2;
9+
</script>
10+
11+
<button on:click={() => show = !show}>
12+
Switch
13+
</button>
14+
15+
<Component>
16+
{@html content}
17+
</Component>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
html: `<p>x<span>baz</span></p>`
3+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>{@html 'x'}<span>baz</span></p>

0 commit comments

Comments
 (0)