-
-
Notifications
You must be signed in to change notification settings - Fork 114
Sorting a keyed each block messes up the DOM #117
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
Comments
Hi, thanks for reporting this. please update the system info in your report with the output of npx envinfo --system --binaries --browsers --npmPackages "{svelte,svelte-hmr,@sveltejs/*,vite}" so we can see which version of vite and vite-plugin-svelte you're using. please also update the reproduction to include steps required, eg which command you used and a link to a repository with complete setup as that repl can't be cloned and is generally nof suitable to reproduce problems with vite-plugin-svelte |
Here it goes:
thanks |
Here's a repro repo: https://github.com/pablote/test-bug To test locally run: |
Note: transferred from sveltejs/svelte#6561 |
Thanks @bluwy for that pointer. @pablote please include original issues in your report. missing cross references cause extra work. Initial observations:
export const sortItems = (items, sortByName) => {
const copy = [...items];
const sortProp = sortByName ? 'name' : 'value'
copy.sort((a,b)=> {
const aVal = a[sortProp], bVal = b[sortProp];
return aVal < bVal ? -1 : (aVal === bVal ? 0 : 1);
})
return copy;
}; It works without animation if you remove the key from the each block. |
It also works with the keyed each when you remove the |
We had a conversation on discord where @dominikg figured out the difference between the REPL and the Vite setup is that |
here's a repo with default svelte template showing it: https://github.com/dominikg/svelte-hydration-reorder-bug closing here, please add additional info in svelte repo |
Describe the bug
I have a keyed each block displaying items. These items can be 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 seems to happen for conditionally renderer elements).
This only seems to happen using Vite and the vite-plugin-svelte plugin.
Reproduction
Here's a link reproducing the issue: https://svelte.dev/repl/e25e9d00d43e4d6eaadf5f3362c47f92?version=3.40.1
You can't see the error itself on the REPL. But the same code on a Vite project has the issue, here's how it looks:
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: