From 47f9c3dbfdfcbb978522da04a50bc50fa1762508 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 23 Jun 2017 17:56:34 -0400 Subject: [PATCH] dont recreate if_blocks incorrectly --- src/generators/dom/visitors/IfBlock.ts | 7 +++- .../_config.js | 37 +++++++++++++++++++ .../main.html | 26 +++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/_config.js create mode 100644 test/runtime/samples/transition-js-if-block-in-each-block-bidi-3/main.html diff --git a/src/generators/dom/visitors/IfBlock.ts b/src/generators/dom/visitors/IfBlock.ts index e7fecebefece..fc2c54ca9738 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 000000000000..bcb5a9e05f68 --- /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 000000000000..d68c95e8b038 --- /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