From 42843868f01b97728ee77dc169c2d51350187548 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Wed, 24 Jun 2020 18:11:04 +0800 Subject: [PATCH 1/3] {@html} moves for slot on update --- .../render_dom/wrappers/RawMustacheTag.ts | 2 +- .../raw-mustache-as-root/RawMustache.svelte | 5 +++ .../samples/raw-mustache-as-root/_config.js | 33 +++++++++++++++++++ .../samples/raw-mustache-as-root/main.svelte | 17 ++++++++++ .../Component.svelte | 2 ++ .../raw-mustache-before-element/_config.js | 32 +++++++++++++++++- .../raw-mustache-before-element/main.svelte | 18 +++++++++- .../raw-mustache-inside-slot/_config.js | 3 ++ .../raw-mustache-inside-slot/main.svelte | 1 + 9 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/raw-mustache-as-root/RawMustache.svelte create mode 100644 test/runtime/samples/raw-mustache-as-root/_config.js create mode 100644 test/runtime/samples/raw-mustache-as-root/main.svelte create mode 100644 test/runtime/samples/raw-mustache-before-element/Component.svelte create mode 100644 test/runtime/samples/raw-mustache-inside-slot/_config.js create mode 100644 test/runtime/samples/raw-mustache-inside-slot/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts index 1e6213cf0210..a5367b207dfc 100644 --- a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts +++ b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts @@ -39,7 +39,7 @@ export default class RawMustacheTagWrapper extends Tag { } else { - const needs_anchor = in_head || (this.next && !this.next.is_dom_node()); + const needs_anchor = in_head || (this.next ? !this.next.is_dom_node() : (!this.parent || !this.parent.is_dom_node())); const html_tag = block.get_unique_name('html_tag'); const html_anchor = needs_anchor && block.get_unique_name('html_anchor'); diff --git a/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte b/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte new file mode 100644 index 000000000000..09b9805a97dc --- /dev/null +++ b/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte @@ -0,0 +1,5 @@ + + +{@html content} \ No newline at end of file diff --git a/test/runtime/samples/raw-mustache-as-root/_config.js b/test/runtime/samples/raw-mustache-as-root/_config.js new file mode 100644 index 000000000000..c87971a7f00f --- /dev/null +++ b/test/runtime/samples/raw-mustache-as-root/_config.js @@ -0,0 +1,33 @@ +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.

+ ` + ); + }, +}; diff --git a/test/runtime/samples/raw-mustache-as-root/main.svelte b/test/runtime/samples/raw-mustache-as-root/main.svelte new file mode 100644 index 000000000000..187e88d19ce3 --- /dev/null +++ b/test/runtime/samples/raw-mustache-as-root/main.svelte @@ -0,0 +1,17 @@ + + + + + + +

This line should be last.

\ No newline at end of file diff --git a/test/runtime/samples/raw-mustache-before-element/Component.svelte b/test/runtime/samples/raw-mustache-before-element/Component.svelte new file mode 100644 index 000000000000..fcabccae4898 --- /dev/null +++ b/test/runtime/samples/raw-mustache-before-element/Component.svelte @@ -0,0 +1,2 @@ + +

This line should be last.

\ No newline at end of file diff --git a/test/runtime/samples/raw-mustache-before-element/_config.js b/test/runtime/samples/raw-mustache-before-element/_config.js index 61288cbb52ce..c87971a7f00f 100644 --- a/test/runtime/samples/raw-mustache-before-element/_config.js +++ b/test/runtime/samples/raw-mustache-before-element/_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-before-element/main.svelte b/test/runtime/samples/raw-mustache-before-element/main.svelte index 69c1d0107d5d..3af0e23f1e58 100644 --- a/test/runtime/samples/raw-mustache-before-element/main.svelte +++ b/test/runtime/samples/raw-mustache-before-element/main.svelte @@ -1 +1,17 @@ -

{@html 'x'}baz

\ No newline at end of file + + + + + + {@html content} + \ No newline at end of file diff --git a/test/runtime/samples/raw-mustache-inside-slot/_config.js b/test/runtime/samples/raw-mustache-inside-slot/_config.js new file mode 100644 index 000000000000..61288cbb52ce --- /dev/null +++ b/test/runtime/samples/raw-mustache-inside-slot/_config.js @@ -0,0 +1,3 @@ +export default { + html: `

xbaz

` +}; diff --git a/test/runtime/samples/raw-mustache-inside-slot/main.svelte b/test/runtime/samples/raw-mustache-inside-slot/main.svelte new file mode 100644 index 000000000000..69c1d0107d5d --- /dev/null +++ b/test/runtime/samples/raw-mustache-inside-slot/main.svelte @@ -0,0 +1 @@ +

{@html 'x'}baz

\ No newline at end of file From 4ec84dc725d999c131568bebf42b48a98ec66d4b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 24 Jun 2020 18:11:05 -0400 Subject: [PATCH 2/3] formatting --- .../raw-mustache-as-root/RawMustache.svelte | 2 +- .../samples/raw-mustache-as-root/main.svelte | 14 +++++++------- .../raw-mustache-before-element/main.svelte | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte b/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte index 09b9805a97dc..d94954f49b24 100644 --- a/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte +++ b/test/runtime/samples/raw-mustache-as-root/RawMustache.svelte @@ -1,5 +1,5 @@ {@html content} \ No newline at end of file diff --git a/test/runtime/samples/raw-mustache-as-root/main.svelte b/test/runtime/samples/raw-mustache-as-root/main.svelte index 187e88d19ce3..7ccce0cd9be9 100644 --- a/test/runtime/samples/raw-mustache-as-root/main.svelte +++ b/test/runtime/samples/raw-mustache-as-root/main.svelte @@ -1,15 +1,15 @@ diff --git a/test/runtime/samples/raw-mustache-before-element/main.svelte b/test/runtime/samples/raw-mustache-before-element/main.svelte index 3af0e23f1e58..a022a68e9597 100644 --- a/test/runtime/samples/raw-mustache-before-element/main.svelte +++ b/test/runtime/samples/raw-mustache-before-element/main.svelte @@ -1,17 +1,17 @@ - {@html content} + {@html content} \ No newline at end of file From 8d3acaebc72b3942d113514393bd19dc3fe200af Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 24 Jun 2020 18:12:02 -0400 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ebb45847671..9650d9e0d683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* 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 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))