From 4c2b9603a12c7e9cd138cb7eb934f41095936b6d Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sat, 25 Aug 2018 13:39:48 -0600 Subject: [PATCH] Fix for each-blocks preventing outros from completing Unkeyed each blocks end up with trailing `null` values that prevent the whole from being outroed. This fixes it so the null values are removed before outroing the remaining blocks. Fixes #1617 --- src/compile/nodes/EachBlock.ts | 1 + .../transition-js-each-block-outro/_config.js | 3 ++ .../_config.js | 29 +++++++++++++++++++ .../main.html | 20 +++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 test/runtime/samples/transition-js-nested-each-delete/_config.js create mode 100644 test/runtime/samples/transition-js-nested-each-delete/main.html diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index cae0aa7352..bb726982df 100644 --- a/src/compile/nodes/EachBlock.ts +++ b/src/compile/nodes/EachBlock.ts @@ -480,6 +480,7 @@ export default class EachBlock extends Node { if (outroBlock && this.compiler.options.nestedTransitions) { const countdown = block.getUniqueName('countdown'); block.builders.outro.addBlock(deindent` + ${iterations} = ${iterations}.filter(Boolean); const ${countdown} = @callAfter(#outrocallback, ${iterations}.length); for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown});` ); diff --git a/test/runtime/samples/transition-js-each-block-outro/_config.js b/test/runtime/samples/transition-js-each-block-outro/_config.js index 5e8b99d88d..0ce6573082 100644 --- a/test/runtime/samples/transition-js-each-block-outro/_config.js +++ b/test/runtime/samples/transition-js-each-block-outro/_config.js @@ -12,5 +12,8 @@ export default { assert.equal( divs[0].foo, undefined ); assert.equal( divs[1].foo, 0.5 ); assert.equal( divs[2].foo, 0.5 ); + + raf.tick( 100 ); + assert.htmlEqual(target.innerHTML, '
a
'); } }; \ No newline at end of file diff --git a/test/runtime/samples/transition-js-nested-each-delete/_config.js b/test/runtime/samples/transition-js-nested-each-delete/_config.js new file mode 100644 index 0000000000..870f90efc4 --- /dev/null +++ b/test/runtime/samples/transition-js-nested-each-delete/_config.js @@ -0,0 +1,29 @@ +export default { + nestedTransitions: true, + skipIntroByDefault: true, + + data: { + visible: true, + things: [ 'a', 'b', 'c' ] + }, + + test ( assert, component, target, window, raf ) { + assert.htmlEqual(target.innerHTML, ` +
a
+
b
+
c
+ `); + + component.set({ things: [ 'a' ] }); + + raf.tick( 100 ); + assert.htmlEqual(target.innerHTML, ` +
a
+ `); + + component.set({ visible: false }); + + raf.tick( 200 ); + assert.htmlEqual(target.innerHTML, ''); + } +}; diff --git a/test/runtime/samples/transition-js-nested-each-delete/main.html b/test/runtime/samples/transition-js-nested-each-delete/main.html new file mode 100644 index 0000000000..e12370703e --- /dev/null +++ b/test/runtime/samples/transition-js-nested-each-delete/main.html @@ -0,0 +1,20 @@ +{#if visible} + {#each things as thing} +
{thing}
+ {/each} +{/if} + +