diff --git a/src/generators/dom/visitors/IfBlock.ts b/src/generators/dom/visitors/IfBlock.ts index e7fecebefe..fc2c54ca97 100644 --- a/src/generators/dom/visitors/IfBlock.ts +++ b/src/generators/dom/visitors/IfBlock.ts @@ -369,8 +369,11 @@ function compoundWithOutros( `; const createNewBlock = deindent` - ${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} ); - ${name}.create(); + ${name} = ${if_blocks}[ ${current_block_index} ]; + if ( !${name} ) { + ${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} ); + ${name}.create(); + } ${name}.${mountOrIntro}( ${parentNode}, ${anchor} ); `; diff --git a/test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/_config.js b/test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/_config.js new file mode 100644 index 0000000000..bcb5a9e05f --- /dev/null +++ b/test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/_config.js @@ -0,0 +1,37 @@ +export default { + data: { + foo: false, + threshold: 5 + }, + + html: ` +
1
+
2
+
3
+
4
+
5
+ `, + + test ( assert, component, target, window, raf ) { + const divs = target.querySelectorAll('div'); + + raf.tick(100); + + component.set({ threshold: 4 }); + raf.tick(150); + component.set({ threshold: 5 }); + raf.tick(200); + + component.set({ threshold: 5.5 }); + + assert.htmlEqual(target.innerHTML, ` +
1
+
2
+
3
+
4
+
5
+ `); + + component.destroy(); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/main.html b/test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/main.html new file mode 100644 index 0000000000..d68c95e8b0 --- /dev/null +++ b/test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/main.html @@ -0,0 +1,26 @@ +{{#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number}} + {{#if foo}} + {{#if threshold >= number}} +
{{number}}
+ {{/if}} + {{else}} + {{#if threshold >= number}} +
{{number}}
+ {{/if}} + {{/if}} +{{/each}} + + \ No newline at end of file