Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kiran-mantana opened this issue Oct 10, 2019 · 14 comments
Open

Comments

@kiran-mantana
Copy link

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

@AkilaDe
Copy link

AkilaDe commented Oct 19, 2019

+1

@stevieoj
Copy link

stevieoj commented Nov 4, 2019

Lets see what your reducer looks like

@oularrea
Copy link

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

@whalemare
Copy link

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

@nicomontanari
Copy link

@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.

@aranda-adapptor
Copy link

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.

@nicomontanari
Copy link

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

@pahmed
Copy link

pahmed commented Jun 24, 2020

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

@apgsn
Copy link

apgsn commented Aug 21, 2020

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.

@leonardo-weber
Copy link

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

@Muhammad-ameen356
Copy link

Same problem, any solution ?

@amit13091992
Copy link

any solutions???

@williamgurzoni
Copy link

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.

@next6leo
Copy link

same here also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests