Esoteric bug regarding <input> and $$restProps
Describe the bug
When...
- There is an array of objects iterated with a keyed
{#each}block - ...and the
{#each}loop contains a component with an<input>element - ...with a value from objects' property
- ...and uses
$$restProps - ...and then the array items are rearranged
- ...the inputs lose their values, values becoming
undefined
This is best explained with a reproduction. Just open the repro and click on the arrows.
Funnily enough, the bug disappears when using <textarea>.
Reproduction
https://svelte.dev/repl/d0ca99922aaf491d83fe421bbc93e2a0?version=3.48.0
Logs
No response
System Info
Bug is reproducible in the REPL on MacOS 11.6.3, Chrome 101
Severity
annoyance
I was also able to hit upon these exact same esoteric conditions. Personally, I hit this while trying to implement drag-and-drop reordering for a component which includes a combo-box type element with an inside. My simplified repro matches exactly with the conditions you have outlined.
Because the combo-box was just a small piece of the larger component I was dragging and dropping, I found it an acceptable workaround in my situation to hide the combo-box with an #if statement while dragging was occurring. This seemed to dodge the problem and was an acceptable enough workaround, but I wish I hadn't needed to resort to that. Thanks for identifying the conditions so well.
I have exactly the same problem. Seems like the last version it worked was in 3.24.1. Maybe related to this fix #5270.
Here is another REPL that shows the working and not working code snippets: https://svelte.dev/repl/9133f0a50f084d98a07ec426e5c9b10b?version=3.49.0
I recently ran across a similar issue (#7633) with <input type="radio">s inside a keyed {#each} block - rearranging them would, under different extremely specific conditions, lead to the wrong one (or none of them) being checked. Is there any chance that's related?
(I tried running my REPL from that issue in 3.24.1, which was mentioned in https://github.com/sveltejs/svelte/issues/7578#issuecomment-1186312855 as working, but it still failed there. Still, it seemed similar enough to be worth mentioning.)
I was facing the same issue today. Happy that I found this ticket. 😅 Any chance that the linked PR will be merged soon? 👀
This should be fixed now in 3.56.0 - https://svelte.dev/repl/d0ca99922aaf491d83fe421bbc93e2a0?version=3.56.0