Skip to content

Starting with v3.39.0 sorting a keyed each block messes up the DOM #6561

Closed
@pablote

Description

@pablote

Describe the bug

I have a keyed each block displaying items. These items can sorted by two different criterias, whenever I resort the items, the DOM of the individual items is changed in a strange way. Div elements within the items are displayed out of order.

This works fine up to version 3.38.3, and starts failing with 3.39.0. It also fails with versions 3.40.0 and 3.40.1.

Reproduction

I'm attaching some screenshots. Here you can see the code as it's seen on the IDE, and then how it's shown on the browser dev tools. Notice how in the browser metrics__title is shown last, while in the IDE it's the first element within an item.
Screen Shot 2021-07-23 at 00 31 22
Screen Shot 2021-07-23 at 00 32 15

I haven't been been able to reproduce this on the REPL, but here's one that is as close as I could with a simple example: https://svelte.dev/repl/6ef13760c89f4fd7af060d0312ca1a71?version=3.40.1

I know this is not ideal, but maybe since I can pin point this to a specific version, it can help narrow down the problem. Removing the key to the each block also fixes the problem, but I need that for animate:flip to work.

Logs

No response

System Info

➜  web git:(develop) ✗ npx envinfo --system --npmPackages svelte,rollup,webpack --binaries --browsers
Need to install the following packages:
  envinfo
Ok to proceed? (y)

  System:
    OS: macOS 11.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 39.97 MB / 16.00 GB
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 16.2.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 7.19.1 - /usr/local/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 92.0.4515.107
    Firefox Developer Edition: 91.0
    Safari: 14.1.1
  npmPackages:
    svelte: ^3.38.3 => 3.40.1

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions