Git Product home page Git Product logo

Comments (5)

rt2zz avatar rt2zz commented on May 17, 2024 1

@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.

rt2zz avatar rt2zz commented on May 17, 2024

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.

felipemartim avatar felipemartim commented on May 17, 2024

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.

gullitmiranda avatar gullitmiranda commented on May 17, 2024

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.

felipemartim avatar felipemartim commented on May 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.