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 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