rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.91k stars 863 forks source link

persistStore callback not called in react-native #851

Open oertels opened 6 years ago

oertels commented 6 years ago

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?

ttruongatl commented 6 years ago

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.

cesarm16 commented 6 years ago

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

oertels commented 6 years ago

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 commented 6 years ago

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.

jannikbuschke commented 6 years ago

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

gaultierq commented 5 years ago

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.

maxammann commented 5 years ago

Is there already a solution to this?

vitorreis commented 5 years ago

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

redux-persist-loading-stuck

vitorreis commented 5 years ago

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

maxammann commented 5 years ago

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

kaiiserni commented 5 years ago

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);
}
pacozaa commented 5 years ago

@kaiiserni Would you mind share the your full code?

I am following.

hinodi commented 5 years ago

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

zomars commented 4 years ago

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! 🤦‍♂️ */ 
}
jgudo commented 1 year ago

Any solution to this?