Skip to content

Updating a keyed {#each} triggers lifecycles in reverse order #3957

Open
@farism

Description

@farism

Describe the bug
Updating a key list causes onDestroy/onMount lifecycles in reverse order

Logs

mount {item: "item 1"}
mount {item: "item 2"}
mount {item: "item 3"}
mount {item: "item 4"}
mount {item: "item 5"}
mount {item: "item 1"}
mount {item: "item 2"}
mount {item: "item 3"}
mount {item: "item 4"}
mount {item: "item 5"}
swapping unkeyed list1
destroy {item: "item 4"}
destroy {item: "item 5"}
swapping keyed list2
destroy {item: "item 5"}
destroy {item: "item 4"}
destroy {item: "item 3"}
destroy {item: "item 2"}
destroy {item: "item 1"}
mount {item: "item 8"}
mount {item: "item 7"}
mount {item: "item 6"}

To Reproduce
https://svelte.dev/repl/e8f06d587e3343ba8b4d1c61d94e380f?version=3.15.0

Expected Behavior
Updating a keyed {#each} block calls lifecycles in natural DOM order

Additional context
I'm kind of relying on the initialization order to be "correct" because I have a set of components that (Parent/Child) and the child component registers itself with the parent. It would be nice if this registration happened in order so that I could use it for things like navigation, or other features.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions