-
Notifications
You must be signed in to change notification settings - Fork 61
fix(analytics-react-native): lazy-load AsyncStorage so customers can opt out (SDKRN-8) #1772
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
Merged
Mercy811
merged 18 commits into
main
from
xinyiye/sdkrn-8-improve-asyncstorage-support-in-analytics-react-native
May 27, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
33d47ec
fix(analytics-react-native): lazy-load AsyncStorage so customers can …
Mercy811 43d050f
fix(analytics-react-native): address review feedback on lazy-load (SD…
Mercy811 50d4393
fix(analytics-react-native): address Copilot review on lazy-load (SDK…
Mercy811 a7cd85c
docs(analytics-react-native): clarify cookieStorage override in opt-o…
Mercy811 20bbead
fix(analytics-react-native): tighten MODULE_NOT_FOUND check to our pa…
Mercy811 0443138
test(react-native-example): exercise AsyncStorage opt-out path in Mae…
Mercy811 268f1a7
style(react-native-example): satisfy prettier in react-native.config.…
Mercy811 bcb137e
docs(react-native-example): correct Maestro comment about package.jso…
Mercy811 354be47
test(react-native-example): wait for toast dismiss between Maestro ta…
Mercy811 64dd46e
fix(react-native-example): show toast synchronously on tap to fix CI …
Mercy811 f2e8b41
docs(analytics-react-native): use 'storage client' instead of 'storag…
cursoragent 6774244
docs(analytics-react-native): clarify userId arg can be undefined or …
cursoragent a9deb57
docs(analytics-react-native): move AsyncStorage opt-out section to do…
Mercy811 4f39d53
refactor(analytics-react-native): use null sentinel for lazy AsyncSto…
Mercy811 72fc413
test(react-native-example): use customer-shaped opt-out recipe in smo…
Mercy811 d99b912
fix(react-native-example): remove stray '>' that broke smoke.yaml YAM…
Mercy811 90ab3a6
feat(react-native-example): inject AMPLITUDE_API_KEY at bundle time (…
Mercy811 9e1ad1c
style(react-native-example): satisfy prettier in babel.config.js (SDK…
Mercy811 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,59 @@ | ||
| appId: org.reactjs.native.example.app | ||
| --- | ||
| # Regression guard for SDKRN-8. | ||
| # | ||
| # This example app exercises the documented AsyncStorage opt-out recipe: | ||
| # | ||
| # 1. @react-native-async-storage/async-storage is NOT declared in this app's | ||
| # package.json. In a pnpm setup, that means there is no top-level | ||
| # node_modules/@react-native-async-storage/async-storage symlink; the JS | ||
| # package only exists nested under .pnpm/..., where RN's autolinking | ||
| # doesn't walk. Pod install therefore leaves RNCAsyncStorage out of the | ||
| # iOS binary (verifiable: `grep -c RNCAsyncStorage ios/Podfile.lock` = 0). | ||
| # | ||
| # 2. App.tsx overrides both storageProvider AND cookieStorage with an | ||
| # in-memory implementation. With both slots overridden, the SDK never | ||
| # reaches its default LocalStorage fallback chain — so getAsyncStorage() | ||
| # is never called, the lazy require to @react-native-async-storage is | ||
| # never triggered, and the package's top-level NativeModule-null throw | ||
| # never fires. | ||
| # | ||
| # If the SDK regresses to its old static `import AsyncStorage` (i.e. anything | ||
| # that requires @react-native-async-storage/async-storage at module-load), | ||
| # the app crashes at boot with: | ||
| # Unhandled JS Exception: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null | ||
| # In that case the title below would never render and this flow fails. | ||
| # | ||
| # We also tap both Track buttons to exercise the SDK's runtime storage paths | ||
| # (event queue + identity update) under the opted-out configuration. App.tsx | ||
| # shows a toast labelled "Amplitude Response" *synchronously* on each tap, so | ||
| # the assertion below verifies the SDK call returned without throwing — without | ||
| # depending on the SDK's promise resolution (which only fires when the event | ||
| # is flushed to api2.amplitude.com, and that's slow / unreachable in CI). | ||
| - launchApp | ||
| - extendedWaitUntil: | ||
| visible: | ||
| text: "Test Amplitude App" | ||
| timeout: 15000 | ||
| - tapOn: "Track Event" | ||
| - extendedWaitUntil: | ||
| visible: | ||
| text: "Amplitude Response" | ||
| timeout: 10000 | ||
| - assertVisible: | ||
| text: "Test Amplitude App" | ||
| # Wait for the first toast to dismiss before tapping the next button, so the | ||
| # second `extendedWaitUntil: Amplitude Response` actually waits for the new | ||
| # toast rather than passing immediately on the lingering one. react-native- | ||
| # toast-message auto-dismisses after ~4s. | ||
| - extendedWaitUntil: | ||
| notVisible: | ||
| text: "Amplitude Response" | ||
| timeout: 10000 | ||
| - tapOn: "Track Identify" | ||
| - extendedWaitUntil: | ||
| visible: | ||
| text: "Amplitude Response" | ||
| timeout: 10000 | ||
| - assertVisible: | ||
| text: "Test Amplitude App" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| module.exports = { | ||
| presets: ['module:@react-native/babel-preset'], | ||
| plugins: [ | ||
| // Mirrors the .env / VITE_AMPLITUDE_API_KEY pattern in | ||
| // .github/actions/e2e-test/action.yml — inlines AMPLITUDE_API_KEY from | ||
| // the build-time shell environment into the JS bundle. CI passes the | ||
| // GitHub secret as an env to the xcodebuild step; local devs can | ||
| // `export AMPLITUDE_API_KEY=…` (or use direnv) before running pnpm ios. | ||
| // With no env var set, App.tsx falls back to the literal 'YOUR_API_KEY'. | ||
| [ | ||
| 'transform-inline-environment-variables', | ||
| {include: ['AMPLITUDE_API_KEY']}, | ||
| ], | ||
| ], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.