From da8c245516590ebb30d710158843c1b5d1e6832a Mon Sep 17 00:00:00 2001 From: Igor Emets Date: Wed, 8 May 2019 14:38:27 +0300 Subject: [PATCH 1/5] Fixing #2668, add null-checks in on_outro callback for IfBlock --- src/compile/render-dom/wrappers/IfBlock.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index f3b5c7f2b2ae..7b0d655a005c 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -319,6 +319,9 @@ export default class IfBlockWrapper extends Wrapper { const destroy_old_block = deindent` @group_outros(); @on_outro(() => { + if (${if_blocks}[${previous_block_index}] === null) { + return; + } ${if_blocks}[${previous_block_index}].d(1); ${if_blocks}[${previous_block_index}] = null; }); @@ -430,6 +433,9 @@ export default class IfBlockWrapper extends Wrapper { ? deindent` @group_outros(); @on_outro(() => { + if (${name} === null) { + return; + } ${name}.d(1); ${name} = null; }); From 25c57a2de00f616b8340c35ad55bffd20c47d621 Mon Sep 17 00:00:00 2001 From: Igor Emets Date: Wed, 8 May 2019 14:39:06 +0300 Subject: [PATCH 2/5] Fixing #2668, add test case "each-block-keyed-containing-self-in-if" --- .../Nested.svelte | 5 ++ .../_config.js | 48 +++++++++++++++++++ .../main.svelte | 17 +++++++ 3 files changed, 70 insertions(+) create mode 100644 test/runtime/samples/each-block-keyed-containing-self-in-if/Nested.svelte create mode 100644 test/runtime/samples/each-block-keyed-containing-self-in-if/_config.js create mode 100644 test/runtime/samples/each-block-keyed-containing-self-in-if/main.svelte diff --git a/test/runtime/samples/each-block-keyed-containing-self-in-if/Nested.svelte b/test/runtime/samples/each-block-keyed-containing-self-in-if/Nested.svelte new file mode 100644 index 000000000000..a9831fc1a9c7 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-containing-self-in-if/Nested.svelte @@ -0,0 +1,5 @@ + + +{item.id} diff --git a/test/runtime/samples/each-block-keyed-containing-self-in-if/_config.js b/test/runtime/samples/each-block-keyed-containing-self-in-if/_config.js new file mode 100644 index 000000000000..36d8b3721868 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-containing-self-in-if/_config.js @@ -0,0 +1,48 @@ +export default { + props: { + list: [ + { id: 1 }, + { id: 2 }, + { id: 3, children: [{ id: 30 }, { id: 31 }, { id: 32 }] }, + ], + activeId: null, + }, + + html: ` + + `, + + test({ assert, component, target }) { + component.activeId = 3; + + assert.htmlEqual(target.innerHTML, ` + + `); + + + component.activeId = null; + + assert.htmlEqual(target.innerHTML, ` + + `); + } +}; diff --git a/test/runtime/samples/each-block-keyed-containing-self-in-if/main.svelte b/test/runtime/samples/each-block-keyed-containing-self-in-if/main.svelte new file mode 100644 index 000000000000..c84a733429d6 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-containing-self-in-if/main.svelte @@ -0,0 +1,17 @@ + + + From 5ff1f8253aee6603238796161ef0653681de4d44 Mon Sep 17 00:00:00 2001 From: Igor Emets Date: Tue, 14 May 2019 13:32:30 +0300 Subject: [PATCH 3/5] Fixing #2668, add test case "each-block-keyed-containing-self-in-if-with-else-branch" --- .../Nested.svelte | 5 ++ .../_config.js | 48 +++++++++++++++++++ .../main.svelte | 19 ++++++++ 3 files changed, 72 insertions(+) create mode 100644 test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/Nested.svelte create mode 100644 test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/_config.js create mode 100644 test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/main.svelte diff --git a/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/Nested.svelte b/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/Nested.svelte new file mode 100644 index 000000000000..a9831fc1a9c7 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/Nested.svelte @@ -0,0 +1,5 @@ + + +{item.id} diff --git a/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/_config.js b/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/_config.js new file mode 100644 index 000000000000..0aebab391c07 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/_config.js @@ -0,0 +1,48 @@ +export default { + props: { + list: [ + { id: 1 }, + { id: 2 }, + { id: 3, children: [{ id: 30 }, { id: 31 }, { id: 32 }] }, + ], + activeId: null, + }, + + html: ` +
    +
  • 1foo
  • +
  • 2foo
  • +
  • 3foo
  • +
+ `, + + test({ assert, component, target }) { + component.activeId = 3; + + assert.htmlEqual(target.innerHTML, ` +
    +
  • 1foo
  • +
  • 2foo
  • +
  • + 3 +
      +
    • 30foo
    • +
    • 31foo
    • +
    • 32foo
    • +
    +
  • +
+ `); + + + component.activeId = null; + + assert.htmlEqual(target.innerHTML, ` +
    +
  • 1foo
  • +
  • 2foo
  • +
  • 3foo
  • +
+ `); + } +}; diff --git a/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/main.svelte b/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/main.svelte new file mode 100644 index 000000000000..5d5c4ba35d12 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-containing-self-in-if-with-else-branch/main.svelte @@ -0,0 +1,19 @@ + + +
    + {#each list as item (item.id)} +
  • + + {#if item.id === activeId && item.children} + + {:else} + foo + {/if} +
  • + {/each} +
From 7440e2fddff42380207cfdea942c970588ac7c43 Mon Sep 17 00:00:00 2001 From: Igor Emets Date: Tue, 14 May 2019 13:35:25 +0300 Subject: [PATCH 4/5] Fixing #2668, remove null-checks from on_outro callback for IfBlock --- src/compile/render-dom/wrappers/IfBlock.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index 7b0d655a005c..f3b5c7f2b2ae 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -319,9 +319,6 @@ export default class IfBlockWrapper extends Wrapper { const destroy_old_block = deindent` @group_outros(); @on_outro(() => { - if (${if_blocks}[${previous_block_index}] === null) { - return; - } ${if_blocks}[${previous_block_index}].d(1); ${if_blocks}[${previous_block_index}] = null; }); @@ -433,9 +430,6 @@ export default class IfBlockWrapper extends Wrapper { ? deindent` @group_outros(); @on_outro(() => { - if (${name} === null) { - return; - } ${name}.d(1); ${name} = null; }); From 1ea012e163f561856e242398436a155c5291cdd2 Mon Sep 17 00:00:00 2001 From: Igor Emets Date: Tue, 14 May 2019 13:36:07 +0300 Subject: [PATCH 5/5] Fixing #2668, add reset outros state after check outros --- src/internal/transitions.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/internal/transitions.js b/src/internal/transitions.js index 3649de2b0c64..09064c25cbfa 100644 --- a/src/internal/transitions.js +++ b/src/internal/transitions.js @@ -23,16 +23,21 @@ function dispatch(node, direction, kind) { let outros; -export function group_outros() { +function reset_outros() { outros = { remaining: 0, callbacks: [] }; } +export function group_outros() { + reset_outros(); +} + export function check_outros() { if (!outros.remaining) { run_all(outros.callbacks); + reset_outros(); } }