svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Esoteric bug regarding <input> and $$restProps

Open arggh opened this issue 3 years ago • 4 comments

Describe the bug

When...

  1. There is an array of objects iterated with a keyed {#each} block
  2. ...and the {#each} loop contains a component with an <input> element
  3. ...with a value from objects' property
  4. ...and uses $$restProps
  5. ...and then the array items are rearranged
  6. ...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

arggh avatar Jun 01 '22 16:06 arggh

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.

jorgebv avatar Jun 09 '22 02:06 jorgebv

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

bztes avatar Jul 16 '22 22:07 bztes

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.)

Rhys-T avatar Jul 17 '22 19:07 Rhys-T

I was facing the same issue today. Happy that I found this ticket. 😅 Any chance that the linked PR will be merged soon? 👀

zeekrey avatar Aug 30 '22 10:08 zeekrey

This should be fixed now in 3.56.0 - https://svelte.dev/repl/d0ca99922aaf491d83fe421bbc93e2a0?version=3.56.0

Conduitry avatar Mar 10 '23 00:03 Conduitry