Skip to content

keys do not persist between app reloads #184

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

Closed
bernhardt1 opened this issue Aug 9, 2019 · 7 comments
Closed

keys do not persist between app reloads #184

bernhardt1 opened this issue Aug 9, 2019 · 7 comments
Labels
platform: iOS This is iOS specific

Comments

@bernhardt1
Copy link

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));

  2. 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
@crobinson42
Copy link

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"

@ElieMyIdea
Copy link

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.

@krizzu krizzu added LEGACY platform: iOS This is iOS specific labels Aug 12, 2019
@crobinson42
Copy link

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

@bernhardt1
Copy link
Author

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.

@MariuszSpeednet
Copy link

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.

@krizzu
Copy link
Member

krizzu commented Aug 22, 2019

@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

@MariuszSpeednet
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: iOS This is iOS specific
Projects
None yet
Development

No branches or pull requests

5 participants