svelte
svelte copied to clipboard
{#key} doesn't destroy old components when a transition started
Describe the bug
A {#key} block should destroy the component of the previous key.
This works most of the time, but when an intro is started the components is not destroyed or removed from the dom.
To reproduce:
Minimal example to reproduce the bug:
<!-- App.svelte -->
<script>
import Child from './Child.svelte'
let index = 0
</script>
{#key index}
<Child on:click={() => {index++}} />
{/key}
<!-- Child.svelte -->
<script>
import { fade } from 'svelte/transition'
import { createEventDispatcher } from 'svelte'
const dispatch = createEventDispatcher()
let visible = false
</script>
<button on:click={() => { visible = true; dispatch('click') }}>Next</button>
{#if visible} <div transition:fade /> {/if}
A REPL to see the bug in action, just press the "Next" button.
Expected behavior Intro animations should be canceled, outros should start and when the outros are completed the component should be destroyed.
Information about your Svelte project: System: OS: macOS 11.2.3 Browsers: Chrome: 89.0.4389.90 Firefox: 87.0 Safari: 14.0.3 Svelte: 3.36.0
Severity This is breaking pages, showing weird duplicate components.
Duplicate of #6150
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Bug still prevalent in the current version: https://svelte.dev/repl/617dd85dcc0649b09a90dd5a1832a981?version=3.38.3
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Bug still here https://svelte.dev/repl/617dd85dcc0649b09a90dd5a1832a981?version=3.44.3
Came here to report the same...
Still experiencing this, it's especially bad when the initial element is overflowing
Also ran into this
me too!
Same here!
This should be fixed in 3.57.0 - https://svelte.dev/repl/617dd85dcc0649b09a90dd5a1832a981?version=3.57.0