Skip to content

Rapidly toggling element with out: transition causes incorrect node removal #13681

@kurmachu

Description

@kurmachu

Describe the bug

When an element with a seperate in: and out: transition (or just an out: transition) is rapidly toggled in a short period (as in, hidden due to state-based {#if condition} being briefly false, and then shown due to being true), it is incorrectly removed from the document after the intro animation finishes. If there is no in:, the outro animation plays instead and the element is hidden, despite the {#if ...} being true.

I've run into this when attempting to handle Form Actions from SvelteKit, with something like {#if form?.error}. If the form is re-submitted this becomes undefined before quickly becoming a value, casing the issue on the element presenting the error.

Reproduction

A REPL which attempts to simulate the issue artificially using timeouts on state:
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACo1QwW7bMAz9FUIr0BhI6-3qOSoG7BN6m3ZwJDolIlOqRKcIDP37IDXYeusOgkTyPfG9t6mZPGY1_NoUTwuqQf2IUe2VXGMt8gW9oNqrHNZka2fMNlEUbdgILTEkgQ3mySEUmFNY4P6d00uaOJNQ4PuKrcejQIjIcIC7LJPgbp58xu674Tq-I84RrewqpjM89v928faF5kYuFTo6ukCWq8eDUcfJnk8prOwebPAhDZDQGQXEQxMWVmmPptnIGLW8UAbKIOF08jgdPYINLMgy9rHBxt7RRRveeprrRh6Pq0hgCGw92fNh23UHvd3cSFqxFF2rsX8H6k8ozXkp2vqQ8VNSlfRG7MLbY0Z5pgXDKru_IyMff62dsoev3f-yqvwb6VtnuBT9upI9--stoI_yov5Zo38Jq3dwxAGaoScwqt5GwQBGNVPOqFLjVHu1BEczoVNDS-p3-QOlBZh6eAIAAA==

Press "quickly toggle" twice to see the issue.
You can also remove in:fade to see how just an outro behaves.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22635
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 20.63 GB / 31.87 GB
  Binaries:
    Node: 22.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.8)
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.269

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions