Rehydrate should do a deep merge only on existing keys
See original GitHub issueOn 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:
- Created 5 years ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We could now also look into #100 which introduces an option to provide a custom merging function with the config.
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 ^^.