Skip to content

[FSSDK-13250] Support AsyncStorage v3 in React Native - #1178

Open
raju-opti wants to merge 2 commits into
masterfrom
raju/async-storage-v3
Open

raju-opti wants to merge 2 commits into
masterfrom
raju/async-storage-v3

Conversation

@raju-opti

Copy link
Copy Markdown
Contributor

Summary

  • AsyncStorage v3 support. v3 removed multiGet in favour of getMany, and no longer exports the AsyncStorageStatic type. The React Native AsyncStorage import shim now adds a multiGet built on getMany when the storage doesn't have one. It keeps the requested key order and returns null for missing keys. The removed type import is replaced with a local AsyncStorageCompat interface. v1/v2 storage is returned unchanged.
  • AsyncStorageCache now extends AsyncStoreWithBatchedGet. It previously only implemented AsyncStore, so getBatchedAsync failed its instanceof check and read stored events with one getItem per key. Its getBatched, and therefore multiGet, was never called. Failed-event retries now read all stored events in one batched call.
  • Wider React Native peer ranges:
    • AsyncStorage <4.0.0 (was <3.0.0)
    • NetInfo <13.0.0 (was <12.0.0)
    • react-native-get-random-values >=1.11.0 <3.0.0 (was ^1.11.0)
    • fast-text-encoding and ua-parser-js are now written as explicit <2.0.0 ranges, allowing the same versions as before. ua-parser-js 2.x is licensed AGPL-3.0, so it stays excluded.
  • Test fix: a leaked mockImplementationOnce in event_processor_factory.react_native.spec.ts was making a later test construct a real AsyncStorageCache.

The peer range was what blocked adopting AsyncStorage v3 (#1177). The multiGet crash described in the issue couldn't actually happen at runtime, because AsyncStorageCache.getBatched was never reached. The second change fixes that, so the v3 shim is now actually used.

Test plan

  • Unit tests (full suite passes, 1100 tests):
    • ensureMultiGet: v1/v2 storage is passed through unchanged; on v3, multiGet is built from getMany and keeps the requested key order even when getMany returns its record in a different order.
    • AsyncStorageCache is an AsyncStoreWithBatchedGet, and its getBatched makes a single multiGet call.
    • getBatchedSync / getBatchedAsync: subclasses of the batched base classes use getBatched; other stores fall back to calling get per key.
  • Manual test, iOS simulator, React Native 0.87.1. Setup: the SDK installed from an npm pack tarball, a custom event dispatcher that always fails, two tracked conversion events, and results checked from device logs only.
    • AsyncStorage 3.1.1: the shim adds multiGet. Retries at about 20s and 40s read both stored events through multiGet → getMany in one call, in the requested key order, and re-dispatch the same event UUIDs.
    • AsyncStorage 2.2.0: the shim leaves the native multiGet untouched, and retries use it.
    • Every peer at its highest allowed version (AsyncStorage 3.1.1, NetInfo 12.0.1, fast-text-encoding 1.0.6, react-native-get-random-values 2.0.0, ua-parser-js 1.0.41):
      • A strict npm install (no --legacy-peer-deps) succeeds with no peer warnings.
      • Retries behave the same as above.
      • crypto.getRandomValues is provided by react-native-get-random-values 2.0.0.
      • The ua_parser export runs without errors.

Issues

🤖 Generated with Claude Code

raju-opti and others added 2 commits September 28, 2026 20:58
AsyncStorageCache now extends AsyncStoreWithBatchedGet so getBatchedAsync
routes failed-event retries through a single multiGet/getMany call instead
of one getItem per key. Widen netinfo to <13 and get-random-values to <3
(verified on RN 0.87), and pin fast-text-encoding/ua-parser-js below 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raju-opti
raju-opti requested review from junaed-optimizely and a balanced review from Copilot and removed request for Copilot October 8, 2026 17:59
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 77.624%. remained the same — raju/async-storage-v3 into master

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

[BUG] React Native cache is incompatible with AsyncStorage v3

2 participants