From 0cc4b91f65956e734ffa26d441f42564f2b339e7 Mon Sep 17 00:00:00 2001 From: Bryan Terce Date: Wed, 19 Jun 2019 16:42:33 -0700 Subject: [PATCH] Fix each blocks not unmounting components correctly (#3056) * Prevent outro from invoking detach multiple times * Add tests for unmounting entries in an each block * Remove redundant function for removing from lookup --- src/runtime/internal/keyed-each.ts | 2 +- .../each-block-keyed-shift/Nested.svelte | 5 ++++ .../samples/each-block-keyed-shift/_config.js | 27 +++++++++++++++++++ .../each-block-keyed-shift/main.svelte | 9 +++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/each-block-keyed-shift/Nested.svelte create mode 100644 test/runtime/samples/each-block-keyed-shift/_config.js create mode 100644 test/runtime/samples/each-block-keyed-shift/main.svelte diff --git a/src/runtime/internal/keyed-each.ts b/src/runtime/internal/keyed-each.ts index 33a5f4d1a6..e18ae61770 100644 --- a/src/runtime/internal/keyed-each.ts +++ b/src/runtime/internal/keyed-each.ts @@ -7,7 +7,7 @@ export function destroy_block(block, lookup) { export function outro_and_destroy_block(block, lookup) { transition_out(block, 1, () => { - destroy_block(block, lookup); + lookup.delete(block.key); }); } diff --git a/test/runtime/samples/each-block-keyed-shift/Nested.svelte b/test/runtime/samples/each-block-keyed-shift/Nested.svelte new file mode 100644 index 0000000000..82df711742 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-shift/Nested.svelte @@ -0,0 +1,5 @@ + + +

{title}

\ No newline at end of file diff --git a/test/runtime/samples/each-block-keyed-shift/_config.js b/test/runtime/samples/each-block-keyed-shift/_config.js new file mode 100644 index 0000000000..44ca8447f0 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-shift/_config.js @@ -0,0 +1,27 @@ +export default { + props: { + titles: [{ name: 'a', }, { name: 'b' }, { name: 'c' }] + }, + + html: ` +

a

+

b

+

c

+ `, + + test({ assert, component, target }) { + component.titles = [{ name: 'b' }, { name: 'c' }]; + + assert.htmlEqual(target.innerHTML, ` +

b

+

c

+ `); + + component.titles = [{ name: 'c' }]; + + assert.htmlEqual(target.innerHTML, ` +

c

+ `); + + } +}; diff --git a/test/runtime/samples/each-block-keyed-shift/main.svelte b/test/runtime/samples/each-block-keyed-shift/main.svelte new file mode 100644 index 0000000000..b8954e17fd --- /dev/null +++ b/test/runtime/samples/each-block-keyed-shift/main.svelte @@ -0,0 +1,9 @@ + + +{#each titles as title (title.name)} + +{/each} \ No newline at end of file