It came to my attention that I've introduced a Breaking change, without properly announcing it.
This is only related to iOS platform. Since version 1.0.2, location where Async Storage kept files was changed: https://github.com/react-native-community/react-native-async-storage/commit/34fb6655083b5addc36fe3d21e53f3cfa3cae8c0
Some time age, issue #40 was raised, saying that smooth transition from Core's Async Storage to Community's was not possible, as data was lost on migration (actually, stored somewhere else). I've merged a fix in #46, to bring back the compatibility.
Now, devs that already transitioned to this repo (pre v1.2.2), planning to upgrade to the latest (v1.2.2), would be left off with the same issue as before - their current local data would not be accessible again.
I can imagine how this can be frustrating, to see no breaking change note in the changelog, yet experiencing different module behavior than expected. If this is a case that you got into - I'm sorry, the blame is all mine.
I wanted to discuss a way to fix this issue, and give pre-v1.2.2 devs ability to upgrade to next versions, without breaking anything on the way.
To make this work, we need to move manifest.json file from old (RNCAsyncLocalStorage_V1) directory to a new, correct one (RCTAsyncLocalStorage_V1), deleting unnecessary folder afterwards. This will ensure that data will be kept and in the right directory.
// pseudo native code
fun migrateToAsyncStorage() {
let oldDir = Dir('RNCAsyncLocalStorage_V1')
let newDir = Dir('RCTAsyncLocalStorage_V1')
if(oldDir.exists) {
moveManifest(oldDir, newDir);
deleteDir(oldDir);
}
}
This could be introduced as Native Module or just a simple check on iOS side, when module is build.
Any feedback as always is appreciated, please let me know what you think.
thanks.
We can execute something at module instantiation by including this code.
@implementation RNCAsyncStorage
{
...
}
...
+ (BOOL)requiresMainQueueSetup {
return YES;
}
- (instancetype)init
{
if (!(self = [super init])) {
return nil;
}
// EXECUTE CODE HERE
return self;
}
...
@end
Now my only "trouble" is finding a clean way to re-use the directory path creation method RCTGetStorageDirectory since it uses a dispatch_once. I don't want duplicate code, but I think I found a way to do it. I'll maybe make a PR soon with an initial proposal and we can work from there. Unless you are currently working on any ideas?
Hey @reilem,
I've checked your implementation at your branch and I like it better. Happy to accept PR with it.
thanks.
Fixed within v1.3.1 release 馃帀