async-storage: Storage is not retained after force quit and re-open of app

Current behavior

Items set via AsyncStorage seem to be cleared on apps that are forced quit and re-opened.

Expected behavior

Storage should persist even if an app is forced quit and also with app updates (but I have not tested this scenario yet).

Repro steps

Follow basic example code https://react-native-async-storage.github.io/async-storage/docs/api#useasyncstorage to get / set an item.

  • on App load, getItem
  • show a modal on first time loading the app and upon clicking the “Accept” button triggers the setItem
  • switch out of the app
  • come back and app state is remembered
  • force quit
  • re-open app
  • modal dialog is shown again but shouldn’t be if state is remembered

I’ve also added Sentry exception calls in the catch but not receiving any errors so I don’t think AsyncStorage is failing.

Environment

  • Platforms tested:
    • Android
    • iOS
    • macOS
    • Windows
  • AsyncStorage version: ^1.13.2
  • Environment:

System: OS: macOS 10.15.7 CPU: (8) x64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz Memory: 751.25 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 15.5.1 - /var/folders/36/vnmypcbj02xf8_c2fp8gnl700000gn/T/yarn–1610253002684-0.4976098686317718/node Yarn: 1.22.10 - /var/folders/36/vnmypcbj02xf8_c2fp8gnl700000gn/T/yarn–1610253002684-0.4976098686317718/yarn npm: 7.3.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.3, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: Not Found IDEs: Android Studio: 4.1 AI-201.8743.12.41.6953283 Xcode: 12.3/12C33 - /usr/bin/xcodebuild Languages: Java: 12.0.1 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Also using Expo SDK 40 in a managed workflow.

  • Logs/Errors that may be relevant:

Might be related to #517

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Expo is supported through using a deprecated version of AsyncStorage (that comes with react-native itself). This was mainly to avoid confusion on which version should be used (community or bundled).

@samtsai Care to provide a code snippet/repo that can reproduce the issue?

To my embarrassment, it was an implementation detail that caused this. Thanks for the clarification @Krizzu and @tido64
I have it working now and published the app to production!

Same here. It is somehow working on an Android emulator device and not working on a real android device (api 21).

To be clear, this is not AsyncStorage not supporting Expo’s managed workflow. It’s the other way around.

Screenshot 2021-01-13 at 20 43 32