Skip to content

Reconciling multiple stores with the same object leads to unexpected behaviour and unwanted side effects #2486

@JaielZeus

Description

@JaielZeus

Describe the bug

When using reconcile to set a store object and reusing the object given to reconcile to set another store object, the code breaks in an unexpected manner. Reusing the same object as a base for reconciliation on two different stores leads to some entanglement that is unexpected.

  • In my example code in the playground I have a baseList object which serves as the data sources
  • There is also a storedList and a derivedList store object, having different use cases to accomplish.
  • In the storedList store object there will be ListEntrys put in as { value: number; } objects.
  • Saved in the derivedList store object are the last 6 entries of the storedList
  • Every click on the "Add" button increments a counter current and puts a new list entry into baseList
  • Then the baseList is deep copied
  • This deep copy is used to reconciliate the storedList store object
  • That same deep copy is used to reconciliate the derivedList store object

After the reconciliation of derivedList, the storedList store object is mutated as well, which is unexpected to me.

I have found, and commented it in the code, 2 possible fixes to this constellation. It seems the reusage of the same underlying object leads to this behaviour when utilizing reconcile.

I have read reconcile is gonna get a rework in the 2.0 version. Will this still be a bug in the new version?

Your Example Website or App

https://playground.solidjs.com/anonymous/41a51eb9-de0c-4293-a35c-2ce85c6be36b

Steps to Reproduce the Bug or Issue

  • Go to the playground and use the example.
  • Click on the "Add" button
  • Notice the console log output.

Expected behavior

The console should put out an array with integers in order, like [1,2,3,4,...] but it puts out wrong values for the first 6 elements after 6 clicks.

Screenshots or Videos

Expected output (after 1 of the 2 fixes in comments applied):

Image

Wrong output:

Image

Code

Image

Platform

  • Browser

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions