Skip to content

Migrate Expo storage directory on iOS #563

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

Conversation

brentvatne
Copy link
Contributor

@brentvatne brentvatne commented Mar 17, 2021

Summary

This solves an issue users encountered with the following process:

  • build app with managed workflow, submit to store, users use it, data saved to RCTAsyncLocalStorage.
  • eject app, build and resubmit, users update app and now @react-native-async-storage/async-storage native module is linked and it looks for data in RCTAsyncLocalStorage_V1, no data found - resulting in data loss.

Something that I noticed while implementing this was that it is theoretically possible (although extremely unlikely) that a user would have both an old storage directory and an Expo storage directory ("RNCAsyncLocalStorage_V1" and "RCTAsyncLocalStorage"). To handle this case, I added RCTGetStoragePathForMigration.

The Android side of this migration is handled in #559

Test Plan

  • Created a managed Expo app: I created a simple app to test this: App.tsx. (expo init with managed Typescript template, expo install @react-native-async-storage/async-storage, then added that code to App.tsx).
  • Built it with managed workflow: expo build:ios -t simulator (it takes about 2 minutes to build, you can access the binary here for the next ~28 days).
  • Ran the app in simulator, pressed button to increment value a few times.
  • Ran expo eject, applied the patch from this PR to my local copy of RNCAsyncStorage.m, then built the project and ran it on the same simulator as the previous step.
  • Observed that the storage directory was migrated successfully - the count remained the same.

Here's a video quick run through the above test plan, skipping the steps that could be done in advance:

post.mp4

(I added !! after the count to make it especially clear that this is a different build)

@krizzu krizzu requested a review from tido64 March 20, 2021 16:40
Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 🎖️ Please address the comment I left, this is crucial. Other than that it looks good to go from my side.

@tido64 mind having a look as well? 🙏

Comment on lines 440 to 444
// Then migrate what's in "Documents/.../RCTAsyncLocalStorage_V1" to "Application
// Support/[bundleID]/RCTAsyncLocalStorage_V1"
RCTStorageDirectoryMigrationCheck(RCTCreateStorageDirectoryPath_deprecated(RCTStorageDirectory),
RCTCreateStorageDirectoryPath(RCTStorageDirectory),
NO);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration needs to be outside of the if statement - it's not related to Expo, but normal RN projects. If someone upgrades from pre 1.8.0 version, the migration to Application Support won't kick in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed this feedback, did manual testing again and works as expected

@brentvatne
Copy link
Contributor Author

Android CI failure is unrelated

Copy link
Member

@tido64 tido64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@krizzu krizzu merged commit 8f19c1b into react-native-async-storage:master Apr 2, 2021
@krizzu
Copy link
Member

krizzu commented Apr 2, 2021

Nice one @brentvatne 👏

@krizzu
Copy link
Member

krizzu commented Apr 2, 2021

🎉 This PR is included in version 1.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants