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

State not retaining when the App reload/Kill the App from Background

Open kiran-mantana opened this issue 5 years ago • 14 comments

I am using redux for maintaining the state in my App, Currently i am having issue in Android OS,

I am using the below dependencies

    "@react-native-community/async-storage": "^1.6.1",
    "react-redux": "^6.0.1",
    "redux": "^4.0.2",
    "redux-logger": "^3.0.6",
    "redux-persist": "6.0.0",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "0.10.14"
    "react-native": "^0.60.5",
 "react": "16.8.6",
    "react-apollo": "^2.1.11",

Below is my Redux configurations

const persistConfig = {
  key: 'root',
  keyPrefix: '',
  storage: AsyncStorage,
};

const persistedReducer = persistReducer(persistConfig, reducer);
const store = createStore(persistedReducer, applyMiddleware(thunk));
const persistor = persistStore(store);

The issue i am facing is the data is saved in state when the app is active, If i am killing the app or app hot reload the app i am not getting the data saved in the state.

I tried to see the db file in terminal using the below comand

adb -d shell "run-as com.appid ls /data/data/com.appid/databases/

It is not showing any list, What might be the problem? Can anyone suggest

kiran-mantana avatar Oct 10 '19 06:10 kiran-mantana

+1

AkilaDe avatar Oct 19 '19 21:10 AkilaDe

Lets see what your reducer looks like

stevieoj avatar Nov 04 '19 12:11 stevieoj

I have the same problem, any solution you found? It only happens to me on Android, In ios it works perfectly

oularrea avatar Nov 21 '19 10:11 oularrea

I tried to see the db file in terminal using the below comand

adb -d shell "run-as com.appid ls /data/data/com.appid/databases/

Your data stored not in database. It is stored in AsyncStorage

whalemare avatar Dec 29 '19 12:12 whalemare

@whalemare AsyncStorage uses a database

On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files. On Android, AsyncStorage will use either RocksDB or SQLite based on what is available.

nicomontanari avatar Jan 07 '20 08:01 nicomontanari

I'm seeing this problem in the wild too and it seems to be related to large store states. How big is your store? We also have nested persist configs and combined reducers so I'm not sure if that is affecting the issue.

aranda-adapptor avatar Apr 07 '20 03:04 aranda-adapptor

I had this issue too, i recommend you to check the data that you save and to save it as little as possible.

nicomontanari avatar Apr 07 '20 08:04 nicomontanari

This happens because of using setInterval to throttle the update in createPersistoid.js, the problem is that setInterval gets paused whenever the app goes to background.

It is not relevant to the size of the object in that case, manually calling flush() will save the data

pahmed avatar Jun 24 '20 10:06 pahmed

When your store is large (>4 Mb) you're more likely to run out of memory on Android. To see the size of your store, you can execute showAsyncStorageContentInDev() on your RN debugger console, and it'll return your current store as a jsonified object, with size and all. If this is your case, then see #199. Fortunately there are some libraries specifically designed to solve this issue, such as redux-persist-filesystem-storage, so be sure to check them out.

apgsn avatar Aug 21 '20 15:08 apgsn

having the same problem in 2023, version 6.0.0, any solutions?

leonardo-weber avatar May 26 '23 20:05 leonardo-weber

Same problem, any solution ?

Muhammad-ameen356 avatar Sep 14 '23 08:09 Muhammad-ameen356

any solutions???

amit13091992 avatar Oct 19 '23 18:10 amit13091992

I do have the same issue, but not using async storage, I'm using file based redux-persist-filesystem-storage. In my case, by analysing the React Native bridge, I can see that it's pretty busy parsing and saving files. I'm still using the original (old) RN architecture, so the bridge still slowing it down. Is any of you using the RN new architecture and still having the issue? Thanks.

williamgurzoni avatar Oct 19 '23 19:10 williamgurzoni

same here also

next6leo avatar Oct 25 '23 09:10 next6leo