Skip to content

reconcile problem when array should replace an object #1973

@jcmonnin

Description

@jcmonnin

Describe the bug

I have a data structure coming as JSON from the server that is put in a store. When a new state from server comes, reconcile is used to update the store in order to keep fine grained updates.

When there is an existing object in store, which should be an array after store update, reconcile shows strange behavior.

Your Example Website or App

https://playground.solidjs.com/anonymous/ab7db9d8-47b6-4fd7-8f0b-fda541030b92

Steps to Reproduce the Bug or Issue

The example below shows the strange behavior of reconcile

const [store, setStore] = createStore({"a":{"b":1}});
setStore(reconcile({"a":[{"b": 1}]}));
console.log("with reconcile", JSON.stringify(store));

outputs:

with reconcile {"a":{"0":{"b":1},"b":1}}

Expected behavior

When not using reconcile the store has the expected state:

const [store, setStore] = createStore({"a":{"b":1}});
setStore({"a":[{"b": 1}]});
console.log("without reconcile", JSON.stringify(store));

outputs:

without reconcile {"a":[{"b":1}]}

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

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