solid icon indicating copy to clipboard operation
solid copied to clipboard

'reconcile' mutates array items

Open DrevaSergii opened this issue 2 years ago • 3 comments

Describe the bug

I want to develop something like Combobox component - input field with a list of suggestions. These suggestions are stored on the server, so I have to use createStore and reconcile to optimise the rendering of the new items. I managed to add search field and display suggestions by field value, but I noticed that reconcile mutates array items and after a while the list displays the same suggestion multiple times.

Your Example Website or App

https://playground.solidjs.com/anonymous/e7f8746a-97f3-4edb-8fcf-041905c5660d

Steps to Reproduce the Bug or Issue

  1. Go to the example
  2. Click on the input
  3. Press 3, press Delete few times.

Expected behavior

As a user, I expected to get the same suggestions while typing, but after some time the list displays the same suggestion multiple times.

Screenshots or Videos

https://github.com/solidjs/solid/assets/27158929/ea9b28cb-6def-47ed-9f97-72ac6994fbcc

DrevaSergii avatar Mar 13 '24 19:03 DrevaSergii

I encounter the identical issue where I am pushing an object into the beginning of an array. When the array's length reaches 2, the first and second elements are identical, including their memory addresses.

phy-lei avatar Mar 15 '24 08:03 phy-lei

@phy-lei I solved the problem by adding key option to reconcile.

sdreva avatar Mar 15 '24 08:03 sdreva

@sdreva Thanks, I tried it and the problem was resolved.

phy-lei avatar Mar 15 '24 08:03 phy-lei