From b55797666a7ee9a98960603a152410951939aa6b Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 4 May 2017 09:23:09 -0400 Subject: [PATCH 1/2] failing test for #561 --- .../component-yield-placement/Modal.html | 6 +++++ .../component-yield-placement/_config.js | 25 +++++++++++++++++++ .../component-yield-placement/main.html | 15 +++++++++++ 3 files changed, 46 insertions(+) create mode 100644 test/runtime/samples/component-yield-placement/Modal.html create mode 100644 test/runtime/samples/component-yield-placement/_config.js create mode 100644 test/runtime/samples/component-yield-placement/main.html diff --git a/test/runtime/samples/component-yield-placement/Modal.html b/test/runtime/samples/component-yield-placement/Modal.html new file mode 100644 index 000000000000..0085a3ef7f97 --- /dev/null +++ b/test/runtime/samples/component-yield-placement/Modal.html @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/component-yield-placement/_config.js b/test/runtime/samples/component-yield-placement/_config.js new file mode 100644 index 000000000000..6e5a7d4b7355 --- /dev/null +++ b/test/runtime/samples/component-yield-placement/_config.js @@ -0,0 +1,25 @@ +export default { + data: { + showModal: true + }, + + html: ` + + + + `, + + test ( assert, component, target, window ) { + const button = target.querySelector( 'button' ); + const click = new window.MouseEvent( 'click' ); + + button.dispatchEvent( click ); + + assert.htmlEqual( target.innerHTML, ` + + `); + } +}; diff --git a/test/runtime/samples/component-yield-placement/main.html b/test/runtime/samples/component-yield-placement/main.html new file mode 100644 index 000000000000..ac8366a9c7a3 --- /dev/null +++ b/test/runtime/samples/component-yield-placement/main.html @@ -0,0 +1,15 @@ +{{#if showModal}} + +

Hello!

+
+{{else}} + +{{/if}} + + \ No newline at end of file From dd2e5e8b2b80346c9ad5e7aa1d0e42cc888cc1d4 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 4 May 2017 09:34:07 -0400 Subject: [PATCH 2/2] mount yield blocks immediately, if yield has a parent node (fixes #561) --- src/generators/dom/visitors/YieldTag.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/generators/dom/visitors/YieldTag.js b/src/generators/dom/visitors/YieldTag.js index aa95cd284e07..81dcb3ad5314 100644 --- a/src/generators/dom/visitors/YieldTag.js +++ b/src/generators/dom/visitors/YieldTag.js @@ -1,9 +1,11 @@ export default function visitYieldTag ( generator, block, state ) { - block.builders.mount.addLine( - `${block.component}._yield && ${block.component}._yield.mount( ${state.parentNode || block.target}, null );` + const parentNode = state.parentNode || block.target; + + ( state.parentNode ? block.builders.create : block.builders.mount ).addLine( + `if ( ${block.component}._yield ) ${block.component}._yield.mount( ${parentNode}, null );` ); block.builders.destroy.addLine( - `${block.component}._yield && ${block.component}._yield.destroy( detach );` + `if ( ${block.component}._yield ) ${block.component}._yield.destroy( detach );` ); } \ No newline at end of file