rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

android - State (update) not persisted while app going in background mode and getting closed #1173

Open toytonic opened 4 years ago

toytonic commented 4 years ago

Hey folks,

The following issue occurs on android only:

I have a listener for appstate changes. When the apps goes into background, an action is dispatched. I then close the app while still in background. The state change caused by this action does not to get persisted. Also manually calling persistor.persist() does not help. I see the action and state change in the devtools. They are gone when rehydrating.

Anybody else experienced the same? Is this intended or is there a restriction in background?

Thanks a lot for your help/ideas!

GeekChao commented 4 years ago

Hey, Do u find any solution to this problem? I ran into the same issue. The only workaround that I came up with is to use 'AsyncStorage.setItem' instead. I am not sure if it is the best way to do it. Speaking of ios, 'redux-persist' will not persist the redux state while u dispatch an action to change the redux state in 'AppState background' handler either if you kill the app directly. Let me know if u have a better idea. Thank you.

toytonic commented 4 years ago

No, I did not find a solution. I could model my use case in a different way to avoid the issue here.

My guess is also that it's not directly related to redux-persist as I did a quick test with timeouts and they also did not fire in background mode

GeekChao commented 4 years ago

Thank you for the reply. I think the code will be executed only in the context of AppState callback for the mobile application.

On Mar 31, 2020, at 7:17 AM, Christian Amon notifications@github.com wrote:

No I did find a solution. I could model my use case in a different way to avoid the issue here.

My guess is also that it's not directly related to redux-persist as I did a quick test with timeouts they also did not fire in background mode

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rt2zz/redux-persist/issues/1173#issuecomment-606564028, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACS33I3EVEMVSDIL54SYXQDRKHGNTANCNFSM4LF4HYBA.

dmarkowski commented 4 years ago

Same problem here.

I am using redux-offline + redux-persist v6. When some actions from the offline queue are dispatched in background mode on Android they change the offline queue on global state but these changes are not persisted on the device storage. Then when I kill the app (when it is still in the background) and open it, actions from offline queue are fired again because changes in the queue were not persisted.

If the app will get back to the foreground (without killing in the background) everything is persisted and works as a charm.

bneigher commented 4 years ago

I've introduced background tasks in my app lately and have come to the conclusion that write operations to the store are not persisting when the app is in the background. Any chance @rt2zz you could help understand where to start to investigate this?

Rel: https://github.com/rt2zz/redux-persist/issues/1136

tawotech commented 2 years ago

Hi guys did anyone come up with a solution to make redux actions update the state while the app is in background ? I'm using Redux-thunk with React Native