Skip to content

Rehydrate should do a deep merge only on existing keys #115

@JohnKis

Description

@JohnKis

On 6.0.0 the rehydrated state is incomplete when the store schema changes. There is a PR to fix this (#114) however there is a scenario it doesn't cater for, and it was suggested that this scenario should be documented in a new issue.

Scenario

If a key has been removed from the store's initialState but still included in the saved state in local storage, the rehydrated state will include the deleted key. This is not ideal as it makes it impossible to remove keys from your store schema. This also applies to nested keys.

Example

Store initial state

{
    "key1": {
        "nestedKey1": "value",
        "nestedKey2": "another value",
    },
    "key2": false
}

Saved state in local storage

{
    "key1": {
        "nestedKey1": "update value",
        "nestedKey2": "another value",
        "nestedKey3": "deleted value"
    },
    "key3": true
}

Expected rehydrated state

{
    "key1": {
        "nestedKey1": "updated value",
        "nestedKey2": "another value",
    },
    "key2": false
}

Actual rehydrated state (on #114)

{
    "key1": {
        "nestedKey1": "updated value",
        "nestedKey2": "another value",
        "nestedKey3": "deleted value"
    },
    "key2": false,
    "key3": true
}

If this issue is fixed, it would also be ideal to remove to redundant keys from local storage as well. However this might be complicated especially on nested keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions