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

persistStore callback not called in react-native

Open oertels opened this issue 6 years ago • 15 comments

In my react-native project, the callback after hydrating is sometimes not being called, if I'm using a debugger. Without debugger, the problem does not appear. It seems to be the same issue as https://github.com/rt2zz/redux-persist/issues/172. The actual effect is that only "persist/PERSIST" is dispatched, but nothing that's waiting for the store to be hydrated.

I'm using it pretty standard, like:

persistStore(store, {}, () => { [...]

To avoid a problem with some promise not resolving on hydrating in react-native, I switched to redux-persist-react-native-fs as a storage, but it does not avoid my current problem.

The packages I'm using are

    "react": "^16.4.0",
    "react-dom": "^16.4.0",
    "react-native": "0.55.4",
    "redux-persist": "^5.10.0",
    "redux-persist-react-native-fs": "^1.0.1",

Anything else I could provide?

oertels avatar Jun 26 '18 11:06 oertels

The callback in persistStore is called in my react-native project with/without a debugger. persistStore(store, {}, () => { console.log('OK'); }); I'm using the same packages version you posted.

ttruongatl avatar Jun 28 '18 17:06 ttruongatl

its happening to me, any solution? It's only on Android

cesarm16 avatar Jul 03 '18 16:07 cesarm16

It appears that it only happens when the remote debugger is used. I'm not sure where to start investigating, because it's unpredictable when it happens.

oertels avatar Jul 04 '18 06:07 oertels

Another observation: If the application is stuck within the circumstances described, you can make it work again by switching apps on the emulator to something else, and then switch back. After that, persist/REHYDRATE is called.

oertels avatar Jul 05 '18 07:07 oertels

I think I have the same problem. While debugger attached I only get a persist/PERSIST and after some 30 secs a timeout action. When not using the debugger I get an persist/REHYDRATE and state is populated. Using a real Android device

Also I can fix it for some time by disabling remote debugging and enabling it again.

possibly related https://github.com/rt2zz/redux-persist/issues/717

jannikbuschke avatar Jul 11 '18 17:07 jannikbuschke

This problem has been here since I have started using this library. It may be quite easy to find a work-around but with a downside: I end up developing my apps using the ios simulator, and therefore they are optimised for ios. If this bug was fixed, I would use android dev env a lot more.

gaultierq avatar Sep 06 '18 12:09 gaultierq

Is there already a solution to this?

maxammann avatar Sep 12 '18 19:09 maxammann

This also happens in my project... no solution so far.

redux-persist-loading-stuck

vitorreis avatar Oct 08 '18 20:10 vitorreis

An update, I have users that reported this bug with the release build. :( I am considering stopping using this library...

vitorreis avatar Oct 11 '18 09:10 vitorreis

Hm, I'm not sure how I exactly fixed this, but here is my redux configuration: https://github.com/Integreat/integreat-react-native-app/blob/develop/src/modules/app/createReduxStore.js#L94

maxammann avatar Oct 11 '18 10:10 maxammann

I have had a similar issue, apparently also with release builds, I think my issue had something to do with how android restores activities and RN. Anyhow adding a simple key check like so did the trick for me:

if (store.getState()._persist) {
  _restore();
} else {
  persistStore(store, null, _restore);
}

kaiiserni avatar Oct 14 '18 14:10 kaiiserni

@kaiiserni Would you mind share the your full code?

I am following.

pacozaa avatar Nov 08 '18 11:11 pacozaa

I have a issue here, but it only happing with release build upload to google playstore and in some devices

hinodi avatar Jul 19 '19 10:07 hinodi

Just in case someone have a similar workflow as mine here is my solution:

function configureStore() {
  if (__DEV__) {
    const middlewares = [thunk].filter(Boolean);
    const enhancer = composeWithDevTools({
    })(applyMiddleware(...middlewares));

    const store = createStore(persistedReducer, {}, enhancer);
    if (module.hot) {
      module.hot.accept(() => {
        store.replaceReducer(require('./reducers').default);
      });
    }
    return store;
  }

  return createStore(persistedReducer, applyMiddleware(thunk)); /* <--- I FORGOT TO ADD THE PERSISTED REDUCER HERE! 🤦‍♂️ */ 
}

zomars avatar Nov 27 '19 22:11 zomars

Any solution to this?

jgudo avatar Aug 14 '22 09:08 jgudo