Async-storage: keys do not persist between app reloads

Created on 9 Aug 2019  路  7Comments  路  Source: react-native-async-storage/async-storage

Current behavior

Async Storage does not persist between app reloads

Expected behavior

expect the storage to persist between app reloads

Repro steps

Theory: It may be due to my environment. I am on RN 0.60.3 but link async-storage manually instead of relying on the auto-linking mechanic. Could this cause an issue?

Steps to reproduce:

  1. store items in storage
    await AsyncStorage.setItem('someItem', JSON.stringify(someItem));
  1. retrieve items to ensure they have been stored
let keys = [];
  try {
    keys = await AsyncStorage.getAllKeys();
  } catch (e) {
    console.log('e', e);
    // read key error
  }

  console.log(keys);
  1. reload application & look for keys
let keys = [];
  try {
    keys = await AsyncStorage.getAllKeys();
  } catch (e) {
    console.log('e', e);
    // read key error
  }

  console.log(keys);
  1. The previously stored keys are no longer present.

Environment

do not use podfile, instead link react-native manually
"@react-native-community/async-storage": "^1.6.1"
"react-native": "0.60.3"

  • occurs on both iOS and android
iOS

Most helpful comment

I too am experiencing this issue the last few days - but only on iOS simulator (iOS 12.4). I only experience this intermittently when using cmd+R to reload the app on the simulator. When I press cmd+D then click "Reload" in the simulator I never lose my AsyncStorage data?!

"@react-native-community/async-storage": "^1.6.1"
"react-native": "0.60.4"

All 7 comments

I too am experiencing this issue the last few days - but only on iOS simulator (iOS 12.4). I only experience this intermittently when using cmd+R to reload the app on the simulator. When I press cmd+D then click "Reload" in the simulator I never lose my AsyncStorage data?!

"@react-native-community/async-storage": "^1.6.1"
"react-native": "0.60.4"

Hello,

I also had this problem before finally realizing that I was still importing the package from react-native in some places. It turns out that this created conflicts between the different libraries on IOS.

I hope this could help you in some way.

@ElieMyIdea 鈽濓笍 Yes, this fixed my issue after changing all usage/imports to use this package only. Thanks for mentioning 馃憤
If anyone is still experiencing, it may be related to a dependency lib using the legacy react-native import too.

Thanks @ElieMyIdea That seems to be the case for me as well.

@crobinson42 I am also finding that my dependencies using the old import may be causing some of the issues too.

I'm using:
"@react-native-community/async-storage": "^1.6.1",
"react-native": "0.60.4",
and still have this error. I've checked and everywhere I was importing AsyncStorage from "@react-native-community/async-storage" (I use it only once to save and once to get value). Now I'm back to importing it from "react-native" and it's working, but this is temporary fix.

@MariuszSpeednet

Probably one of your dependency is still using Async Storage from the core - there's a condition race if that's the case. You can read more about it here

@Krizzu
Thanks! It was redux-persist. It seems that I need to set store manually to AsyncStorage.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YogiHa picture YogiHa  路  6Comments

exotexot picture exotexot  路  3Comments

Blackpinned picture Blackpinned  路  3Comments

avinashlng1080 picture avinashlng1080  路  6Comments

Riant picture Riant  路  4Comments