Comments (5)
@felipemartim I forgot to update here, we now set initialState to an empty object, so state will always persist after the first load, thus solving your issue and also enabling https://github.com/wildlifela/redux-persist-migrate
@gullitmiranda that is true, but in idiomatic redux if you do not modify state you return the object as is with referential equality. e.g.
let a ={}
let b = {}
a === b // false
a === a // true
from redux-persist.
persistor is paused until getStoredState is complete otherwise there could potentially be a race condition where state is stored via the persistor before the old state is retrieved, thus overwriting the state that was intended for rehydration.
Your particular case is pretty interesting, we should definitely account for it. One option which I have no fully considered the consequences of would be to set lastState to be the value of the restoredState. This would presumably need to be done when resume() is called.
As a short term workaround you might consider cloning your initialState on logout, so instead of
myReducer (state = initialState, action) {
// ... old way
case 'LOGOUT'
return initialState
// ... new way
case 'LOGOUT'
return {...initialState}
from redux-persist.
Thanks for the quick reply!
I believe that short term workaround wouldn't work for me, due to the fact that my initial state is an Immutable Record. But I'll give it a try later. For now, I'm just returning the initial state with a "hasSignedOut" flag set to true, so it will be different than the initial state.
And I also believe setting lastState to the restoredState would solve the issue. 👍
from redux-persist.
the comparison of objects in javascript does not work very well. Thus the state[key] == reducedState[key]
(in /src/autoRehydrate.js#L29) will always return false if the content is an object.
e.g.:
$ node --version
v6.0.0
$ node
> a = {"_status":null,"data":null,"entities":{},"model":{},"errors":null,"error":null}
{ _status: null,
data: null,
entities: {},
model: {},
errors: null,
error: null }
> b = {"_status":null,"data":null,"entities":{},"model":{},"errors":null,"error":null}
{ _status: null,
data: null,
entities: {},
model: {},
errors: null,
error: null }
> a == b
false
> a !== b
true
from redux-persist.
@gullitmiranda, as I'm using Immutable.js Records, this equality check returns true. However, after upgrading to 3.1.0, the issue got solved for me, so I'm closing this.
Thanks @rt2zz !
from redux-persist.
Related Issues (20)
- Importing PersistGate results in compilation error HOT 1
- Jest snapshot is always created as null in react native
- Persist not working after page reload or refresh HOT 3
- failed to preserved initial state value at rehydrate
- PersistGate in SSR applications rendering app twice when using React v18 HOT 3
- Documentation for Migration is unnecessary complicated. HOT 1
- Getting got unexpected undefined error while changing redux state HOT 1
- getting error: A non-serializable value was detected in an action HOT 5
- createStore() is old
- Clear Redux Persist Data on App uninstall in IOS React Native HOT 1
- Support for Redux v5 and RTK v2 HOT 10
- state is null HOT 1
- data migration security and automatization
- Redux persist not working with RN 0.73 HOT 10
- Move project to new repo? HOT 13
- redux-persist failed to create sync storage. falling back to noop storage | Next js HOT 3
- Vitest - The slice reducer for key "reducer name" returned undefined during initialization
- Option to disable storage creation error for dynamic stores
- storage.getItem is not a function (it is undefined) - RN 0.73.4 HOT 3
- Redux persist getting cleared after persisting PatientsReducers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-persist.