diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4e588c9a..e2886ec110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * Support nullish coalescing (`??`) and optional chaining (`?.`) operators ([#1972](https://github.com/sveltejs/svelte/issues/1972)) * Support `import.meta` ([#4379](https://github.com/sveltejs/svelte/issues/4379)) -* Fix placement of `{@html}` when used at the root of a slot or the root of a component ([#5012](https://github.com/sveltejs/svelte/issues/5012)) +* Fix placement of `{@html}` when used at the root of a slot, at the root of a component, or in `` ([#5012](https://github.com/sveltejs/svelte/issues/5012), [#5071](https://github.com/sveltejs/svelte/pull/5071)) * Fix handling of `import`ed value that is used as a store and is also mutated ([#5019](https://github.com/sveltejs/svelte/issues/5019)) * Do not display `a11y-missing-content` warning on elements with `contenteditable` bindings ([#5020](https://github.com/sveltejs/svelte/issues/5020)) * Fix handling of `this` in inline function expressions in the template ([#5033](https://github.com/sveltejs/svelte/issues/5033)) diff --git a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts index a5367b207d..7d3f727ab1 100644 --- a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts +++ b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts @@ -51,7 +51,7 @@ export default class RawMustacheTagWrapper extends Tag { content => x`${html_tag}.p(${content})` ); - const update_anchor = in_head ? 'null' : needs_anchor ? html_anchor : this.next ? this.next.var : 'null'; + const update_anchor = needs_anchor ? html_anchor : this.next ? this.next.var : 'null'; block.chunks.hydrate.push(b`${html_tag} = new @HtmlTag(${update_anchor});`); block.chunks.mount.push(b`${html_tag}.m(${init}, ${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`); diff --git a/test/runtime/samples/raw-mustache-before-element/_config.js b/test/runtime/samples/raw-mustache-before-element/_config.js index c87971a7f0..61288cbb52 100644 --- a/test/runtime/samples/raw-mustache-before-element/_config.js +++ b/test/runtime/samples/raw-mustache-before-element/_config.js @@ -1,33 +1,3 @@ export default { - html: ` - -

Another first line

-

This line should be last.

- `, - async test({ assert, target, window }) { - const btn = target.querySelector("button"); - const clickEvent = new window.MouseEvent("click"); - - await btn.dispatchEvent(clickEvent); - - assert.htmlEqual( - target.innerHTML, - ` - -

First line

-

This line should be last.

- ` - ); - - await btn.dispatchEvent(clickEvent); - - assert.htmlEqual( - target.innerHTML, - ` - -

Another first line

-

This line should be last.

- ` - ); - }, + html: `

xbaz

` }; diff --git a/test/runtime/samples/raw-mustache-before-element/main.svelte b/test/runtime/samples/raw-mustache-before-element/main.svelte index a022a68e95..69c1d0107d 100644 --- a/test/runtime/samples/raw-mustache-before-element/main.svelte +++ b/test/runtime/samples/raw-mustache-before-element/main.svelte @@ -1,17 +1 @@ - - - - - - {@html content} - \ No newline at end of file +

{@html 'x'}baz

\ No newline at end of file diff --git a/test/runtime/samples/raw-mustache-inside-head/_config.js b/test/runtime/samples/raw-mustache-inside-head/_config.js new file mode 100644 index 0000000000..4a84f5c01d --- /dev/null +++ b/test/runtime/samples/raw-mustache-inside-head/_config.js @@ -0,0 +1,16 @@ +export default { + async test({ assert, target, window }) { + const btn = target.querySelector("button"); + const clickEvent = new window.MouseEvent("click"); + + assert.equal(window.document.head.innerHTML.includes(''), true); + + await btn.dispatchEvent(clickEvent); + + assert.equal(window.document.head.innerHTML.includes(''), true); + + await btn.dispatchEvent(clickEvent); + + assert.equal(window.document.head.innerHTML.includes(''), true); + }, +}; diff --git a/test/runtime/samples/raw-mustache-inside-head/main.svelte b/test/runtime/samples/raw-mustache-inside-head/main.svelte new file mode 100644 index 0000000000..25b9fdeee9 --- /dev/null +++ b/test/runtime/samples/raw-mustache-inside-head/main.svelte @@ -0,0 +1,16 @@ + + + + + + {@html content} + + diff --git a/test/runtime/samples/raw-mustache-before-element/Component.svelte b/test/runtime/samples/raw-mustache-inside-slot/Component.svelte similarity index 100% rename from test/runtime/samples/raw-mustache-before-element/Component.svelte rename to test/runtime/samples/raw-mustache-inside-slot/Component.svelte diff --git a/test/runtime/samples/raw-mustache-inside-slot/_config.js b/test/runtime/samples/raw-mustache-inside-slot/_config.js index 61288cbb52..c87971a7f0 100644 --- a/test/runtime/samples/raw-mustache-inside-slot/_config.js +++ b/test/runtime/samples/raw-mustache-inside-slot/_config.js @@ -1,3 +1,33 @@ export default { - html: `

xbaz

` + html: ` + +

Another first line

+

This line should be last.

+ `, + async test({ assert, target, window }) { + const btn = target.querySelector("button"); + const clickEvent = new window.MouseEvent("click"); + + await btn.dispatchEvent(clickEvent); + + assert.htmlEqual( + target.innerHTML, + ` + +

First line

+

This line should be last.

+ ` + ); + + await btn.dispatchEvent(clickEvent); + + assert.htmlEqual( + target.innerHTML, + ` + +

Another first line

+

This line should be last.

+ ` + ); + }, }; diff --git a/test/runtime/samples/raw-mustache-inside-slot/main.svelte b/test/runtime/samples/raw-mustache-inside-slot/main.svelte index 69c1d0107d..a022a68e95 100644 --- a/test/runtime/samples/raw-mustache-inside-slot/main.svelte +++ b/test/runtime/samples/raw-mustache-inside-slot/main.svelte @@ -1 +1,17 @@ -

{@html 'x'}baz

\ No newline at end of file + + + + + + {@html content} + \ No newline at end of file