Skip to content

Commit

Permalink
Fix each blocks not unmounting components correctly (#3056)
Browse files Browse the repository at this point in the history
* Prevent outro from invoking detach multiple times

* Add tests for unmounting entries in an each block

* Remove redundant function for removing from lookup
  • Loading branch information
btk5h authored and Rich-Harris committed Jun 19, 2019
1 parent f9054bc commit 7b5f176
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/internal/keyed-each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
5 changes: 5 additions & 0 deletions test/runtime/samples/each-block-keyed-shift/Nested.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let title;
</script>

<p>{title}</p>
27 changes: 27 additions & 0 deletions test/runtime/samples/each-block-keyed-shift/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default {
props: {
titles: [{ name: 'a', }, { name: 'b' }, { name: 'c' }]
},

html: `
<p>a</p>
<p>b</p>
<p>c</p>
`,

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

assert.htmlEqual(target.innerHTML, `
<p>b</p>
<p>c</p>
`);

component.titles = [{ name: 'c' }];

assert.htmlEqual(target.innerHTML, `
<p>c</p>
`);

}
};
9 changes: 9 additions & 0 deletions test/runtime/samples/each-block-keyed-shift/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import Nested from './Nested.svelte';
export let titles;
</script>

{#each titles as title (title.name)}
<Nested title="{title.name}"/>
{/each}

0 comments on commit 7b5f176

Please sign in to comment.