redux-persist
redux-persist copied to clipboard
persistStore callback not called in react-native
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?
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.
its happening to me, any solution? It's only on Android
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.
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.
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
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.
Is there already a solution to this?
This also happens in my project... no solution so far.
An update, I have users that reported this bug with the release build. :( I am considering stopping using this library...
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
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 Would you mind share the your full code?
I am following.
I have a issue here, but it only happing with release build upload to google playstore and in some devices
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! 🤦♂️ */
}
Any solution to this?