-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
Components are not destroyed when they are removed from their parent node while that node is currently running its exit transition.
Example: I have a component in a div that has a fade transition, and I remove the component while that div is fading out. The component is not destroyed correctly. It is gone from the DOM, but still "alive" (store subscriptions not closed, onDestroy not called, etc).
To Reproduce
I have created a small REPL example that reproduces the issue.
Note how the console only logs the onDestroy call for the Outer component, but NOT the inner component when you click on the "Close" button.
If you remove "transition:fade" in App.svelte:9 then everything works correctly.
https://svelte.dev/repl/eff9e77c7d5c41059616211e46f3f021?version=3.24.1
The example is a bit artificial of course. In our actual application we have a lot of stores subscribed to realtime updates via websocket. It can frequently happen that you switch/navigate between different content (using transitions) and an update just happens to arrive for the "old" content while the transition is active.
Expected behavior
onDestroy should be called / component should be destroyed when using transitions.
Information about your Svelte project:
-
Your browser and the version: Chrome 84.0.4147.125 (Official Build) (64-bit)
-
Your operating system: OSX 10.15.5
-
Svelte version: 3.24.1
Severity
Now that I managed to trace down the cause of this issue it is not that severe, as it's easy to work around; it just blocks us from using transitions / some third party components that rely on them.
However before I managed to isolate it was extremely frustrating as it appeared as seemingly "random" behaviour with some components not unmounting / resulting in dangling store subscriptions and associated weirdness.