From f9fbefe5ebf63af92bea608b13fc745916b886d3 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Tue, 25 Jun 2019 08:43:09 -0400 Subject: [PATCH] fix #3035 for real --- .../compile/render_dom/wrappers/EachBlock.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index b57ce46b29..6f592d3869 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -445,13 +445,18 @@ export default class EachBlockWrapper extends Wrapper { } ` : deindent` - ${iterations}[#i] = ${create_each_block}(child_ctx); - ${iterations}[#i].c(); - ${has_transitions && `@transition_in(${this.vars.iterations}[#i], 1);`} - ${iterations}[#i].m(${update_mount_node}, ${anchor}); + if (${iterations}[#i]) { + ${has_transitions && `@transition_in(${this.vars.iterations}[#i], 1);`} + } else { + ${iterations}[#i] = ${create_each_block}(child_ctx); + ${iterations}[#i].c(); + ${has_transitions && `@transition_in(${this.vars.iterations}[#i], 1);`} + ${iterations}[#i].m(${update_mount_node}, ${anchor}); + } + `; - const start = this.block.has_update_method ? '0' : `${view_length}`; + const start = this.block.has_update_method ? '0' : `old_length`; let remove_old_blocks; @@ -470,7 +475,7 @@ export default class EachBlockWrapper extends Wrapper { `; } else { remove_old_blocks = deindent` - for (${this.block.has_update_method ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${view_length}; #i += 1) { + for (${this.block.has_update_method ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${this.block.has_update_method ? view_length : 'old_length'}; #i += 1) { ${iterations}[#i].d(1); } ${!fixed_length && `${view_length} = ${this.vars.each_block_value}.${length};`} @@ -478,6 +483,7 @@ export default class EachBlockWrapper extends Wrapper { } const update = deindent` + ${!this.block.has_update_method && `const old_length = ${this.vars.each_block_value}.length;`} ${this.vars.each_block_value} = ${snippet}; for (var #i = ${start}; #i < ${this.vars.each_block_value}.${length}; #i += 1) {