Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix each blocks not unmounting components correctly #3056

Merged
merged 3 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/runtime/internal/keyed-each.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { transition_in, transition_out } from './transitions';

export function remove_block_from_lookup(block, lookup) {
btk5h marked this conversation as resolved.
Show resolved Hide resolved
lookup.delete(block.key);
}

export function destroy_block(block, lookup) {
block.d(1);
lookup.delete(block.key);
remove_block_from_lookup(block, lookup);
}

export function outro_and_destroy_block(block, lookup) {
transition_out(block, 1, () => {
destroy_block(block, lookup);
remove_block_from_lookup(block, lookup);
});
}

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}