-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Starting with v3.39.0 sorting a keyed each block messes up the DOM #6561
Comments
Some more info. I can confirm that the elements wrongly placed after sorting are conditionally rendered. If I comment out the if around the title, the problem is fixed, for the title at least. There's still problems with other elements though. I'm still trying to repro this on a simplified REPL btw, with no success. |
@Conduitry I've been able to reproduce this with a simple example, thing is, apparently this only happens when using Vite with the This is the repro code (though it works on the REPL): https://svelte.dev/repl/e25e9d00d43e4d6eaadf5f3362c47f92?version=3.40.1 |
If you're able to repro with the latest version of vite-plugin-svelte, I'd say we should move this to https://github.com/sveltejs/vite-plugin-svelte/issues |
Reproduction with plain svelte template: https://github.com/dominikg/svelte-hydration-reorder-bug The issue is caused by |
Also note that if you remove the wrapping |
I believe https://github.com/hbirler/svelte/tree/append-fix might be the fix. |
updated repro to 3.41, still happening. https://github.com/dominikg/svelte-hydration-reorder-bug @hbirler are you sure append is the right fix? this one not happening on initial hydration but when keyed children of an each loop are reordered. i'd not expect hydration to run again at that point |
@dominikg I believe the hydration version of the append function is still called after the initial hydration. They are only called with |
It seemed to fix the issue for me locally. Does it not work for you? Maybe I made a mistake. |
Additionally, the new non-hydration
|
@hbirler the change make sense, would you mind creating a pull request with a new test case 🙏🏻 ? |
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.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
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: