question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rehydrate should do a deep merge only on existing keys

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
moniuchcommented, Jan 21, 2019

We could now also look into #100 which introduces an option to provide a custom merging function with the config.

1reaction
moniuchcommented, Jan 19, 2019

Thank you so much!

@bufke David, what would you say if we provided an issue template with instructions for the users who want to submit a bug ticket, asking them to provide their config and actual/expected state? Just the way @JohnKis did ^^.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deep merge instead of shallow merge? - Stack Overflow
I know this is a bit of an old issue but the easiest solution in ES2015/ES6 I could come up with was actually...
Read more >
Persist state with Redux Persist using Redux Toolkit in React
With the Redux Persist library, developers can save the Redux ... that gets persisted and rehydrated, all with an easily understandable API.
Read more >
Documentation - SolidJS · Reactive Javascript Library
In Solid, you often don't need to wrap functions in memos; you can alternatively just define and call a regular function to get...
Read more >
How to Keep NgRx State on Refresh | Nils Mehlhorn
You can't really ask your users to install a browser extension. So, read on if you want to re-hydrate the store to improve...
Read more >
Managing Multiple-Organization Accounts - Datadog Docs
The parent-organization can view the usage of child-organizations by existing tag keys in the Usage Attribution page. Admins can hover over their username ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found