diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index dbb1d2c085..5a1a71d16c 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -66,12 +66,16 @@ export default function visitEachBlock ( generator, block, state, node ) { ${each_block_else}.mount( ${anchor}.parentNode, ${anchor} ); } else if ( ${each_block_else} ) { ${each_block_else}.destroy( true ); + ${each_block_else} = null; } ` ); } else { block.builders.update.addBlock( deindent` if ( ${each_block_value}.length ) { - if ( ${each_block_else} ) ${each_block_else}.destroy( true ); + if ( ${each_block_else} ) { + ${each_block_else}.destroy( true ); + ${each_block_else} = null; + } } else if ( !${each_block_else} ) { ${each_block_else} = ${node.else._block.name}( ${params}, ${block.component} ); ${each_block_else}.mount( ${anchor}.parentNode, ${anchor} ); diff --git a/test/runtime/samples/each-block-dynamic-else-static/_config.js b/test/runtime/samples/each-block-dynamic-else-static/_config.js index 6508c6ba5e..a10c4600b3 100644 --- a/test/runtime/samples/each-block-dynamic-else-static/_config.js +++ b/test/runtime/samples/each-block-dynamic-else-static/_config.js @@ -23,5 +23,10 @@ export default { assert.htmlEqual( target.innerHTML, `
wombat
` ); + + component.set({ animals: ['dinosaur'] }); + assert.htmlEqual( target.innerHTML, ` +dinosaur
+ ` ); } };