redux-reset icon indicating copy to clipboard operation
redux-reset copied to clipboard

Problems with redux-persist v5

Open giacomocerquone opened this issue 7 years ago • 7 comments

Hi, I believe this package has some issues with redux-persist v5. Basically it's like it resets the state but the redux-persist package for some reason doesn't write the updated state to the storage system (asyncstorage in my situation).

But if I create a reset action by hand (that brings the state to its initial state), it works correctly. I'm integrating your package like this:

createStore(
  rootReducer,
  undefined,
  compose(
    applyMiddleware(
      thunkMiddleware,
      loggerMiddleware,
    ),
    reduxReset('RESET_APP')
  )
)

What may be causing this issue?

giacomocerquone avatar Dec 11 '17 14:12 giacomocerquone

@giacomocerquone did you find a solution to this ?

ritz078 avatar Dec 29 '17 11:12 ritz078

I have the same problem here for "redux-persist": "5.4.0". Can you please help to find a solution

DavitVosk avatar Feb 09 '18 19:02 DavitVosk

@ritz078 no, for now I made myself happy using handmade RESET actions

giacomocerquone avatar Feb 10 '18 00:02 giacomocerquone

Yes @giacomocerquone, I make it by hand as well and it works. But it would be better if this package could handle it itself as it has to do

DavitVosk avatar Feb 10 '18 07:02 DavitVosk

I'm not using redux-reset (implemented a solution myself), but came across the same issue. It seems redux-persist doesn't like 'reseting' the state. We resolved the situation by pausing the persistor ((persistor.pause()) before setting the store state, then resuming (persistor.persist()) it right after reseting, and everything works fine. So we get a flow like: pause persistence -> reset store state -> resume persistence.

Hope it helps!

GlisboaDev avatar Apr 02 '19 18:04 GlisboaDev

When we reset our state and purge storage, state is not persisted anymore - running persistor.persist() solves this issue.

Example code:

export function logout() {
  return async dispatch => {
    dispatch({ type: 'RESET' })
    await persistor.purge()
    await persistor.persist()
  }
}

milasevicius avatar May 28 '19 07:05 milasevicius

I had the same issue. It seems like { type: 'RESET' } will remove the _persistor state and it causes redux-persist not to persist anymore. I found it will be persisted if you pass an initial state.

dispatch({
  type: 'RESET',
  state: {
    _persist: { version: 1, rehydrated: true }
  }
})

I hope this helps.

foloinfo avatar Oct 11 '21 08:10 foloinfo