pull/9913/head
Dominic Gannaway 7 months ago committed by GitHub
parent b1efd8c4cd
commit 2608e621d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: cleanup each block animations on destroy

@ -744,17 +744,27 @@ export function destroy_each_item_block(
const transitions = block.s;
if (apply_transitions && transitions !== null) {
trigger_transitions(transitions, 'out');
if (transition_block !== null) {
transition_block.push(block);
// We might have pending key transitions, if so remove them first
for (let other of transitions) {
if (other.r === 'key') {
transitions.delete(other);
}
}
} else {
const dom = block.d;
if (!controlled && dom !== null) {
remove(dom);
if (transitions.size === 0) {
block.s = null;
} else {
trigger_transitions(transitions, 'out');
if (transition_block !== null) {
transition_block.push(block);
}
return;
}
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (block.e));
}
const dom = block.d;
if (!controlled && dom !== null) {
remove(dom);
}
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (block.e));
}
/**

@ -0,0 +1,60 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
async test({ assert, target, window }) {
const button = target.querySelector('button');
ok(button);
assert.htmlEqual(
target.innerHTML,
`
<button>Remove last</button><div class="list"><label><input type="checkbox">
write
some
docs</label><label><input type="checkbox">
start
writing
JSConf
talk</label><label><input type="checkbox">
buy
some
milk</label><label><input type="checkbox">
mow
the
lawn</label><label><input type="checkbox">
feed
the
turtle</label><label><input type="checkbox">
fix
some
bugs</label></div>`
);
flushSync(() => {
button.click();
});
assert.htmlEqual(
target.innerHTML,
`
<button>Remove last</button><div class="list"><label><input type="checkbox">
write
some
docs</label><label><input type="checkbox">
start
writing
JSConf
talk</label><label><input type="checkbox">
buy
some
milk</label><label><input type="checkbox">
mow
the
lawn</label><label><input type="checkbox">
feed
the
turtle</label></div>`
);
}
});

@ -0,0 +1,28 @@
<script>
import { flip } from 'svelte/animate';
let todos = [
{ id: 1, done: false, description: 'write some docs' },
{ id: 2, done: false, description: 'start writing JSConf talk' },
{ id: 3, done: true, description: 'buy some milk' },
{ id: 4, done: false, description: 'mow the lawn' },
{ id: 5, done: false, description: 'feed the turtle' },
{ id: 6, done: false, description: 'fix some bugs' }
];
function update() {
todos = [...todos]
todos.pop();
}
</script>
<button on:click={update}>Remove last</button>
<div class="list">
{#each todos as todo (todo.id)}
<label animate:flip>
<input type="checkbox" bind:checked={todo.done} />
{todo.description}
</label>
{/each}
</div>
Loading…
Cancel
Save