From a0a7583fb826a31611f57f70ef699fc50699f3d7 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 19 Apr 2017 10:39:45 -0400 Subject: [PATCH] =?UTF-8?q?null=20out=20else=20block=20references=20when?= =?UTF-8?q?=20they=20are=20destroyed=20=E2=80=94=20fixes=20#509?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/generators/dom/visitors/EachBlock.js | 6 +++++- .../samples/each-block-dynamic-else-static/_config.js | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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

+ ` ); } };