-
Notifications
You must be signed in to change notification settings - Fork 467
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
core asyncstorage and community version #118
Comments
Hi @rogueturnip, Thanks for bringing this up. Could you provide a repo where the issue is reproducible? Would be helpful in further debugging. Also, what platform are you seeing this? thanks |
Sorry I don't actually have this in a public repo. The app is private so I can't open it up. The problem only occurs with ios and only with the aws amplify asyncstorage. Android everything works fine.I Tomorrow I will try adding in the old asyncstorage in my code to add something and see if I get the same issue. |
I did a simple test this morning. In my main app code I set up the old AsyncStorage from react-native core along with the new AsyncStorage from react-community. The core one did not persist through an IOS app restart but the react-community one did. I don't have a repo for you to see this but it's a very simple set up, 2 lines of code with each writing something different to asyncstorage. Still no issues on Android. |
@rogueturnip right. Can you provide some code samples? It's important how you call those two "writings" to AS. thanks |
Hi! So obviously my code has a bunch more in it but basically I'm calling it like below. My real concern is that is if there is a special way to make these work correctly together that the library "aws-amplify" which uses the old asyncstorage won't work right. Thanks!
|
@rogueturnip Try out making those calls wait for results, before going further. class TestApp extends Component {
constructor(props) {
super(props);
this.saveIt()
}
saveIt = async () => {
await oldAS.setItem('oldtest','testing old');
await AsyncStorage.setItem('newtest', 'testing new');
}
render() {
return null;
}
} |
Thanks for that. I tried it with await and it's giving me the same results on ios. |
@rogueturnip you mean it's still an issue for you? |
Yes, I'm still having the original AsyncStorage not saving across reloads of the iOS app. it's only iOS. I wanted to point that out in case it's something related to the linking that's causing the issue. |
The implementation of Async Storage (both Comms and core one) for iOS is based on writing/reading from a file. This is the same file for both versions (so during the transition from the core to Community's AS, you won't lose data). There's this comment left from original authors. This tiny detail is the key to understand the problem. Each time your app restarts (or you reload the bundle), storage's file is read to the This is a condition race. The last call to My advice here:
There's Async Storage v2 coming, with a different approach for storage capabilities, making it more transparent and less error-prone in the future. Please look forward to it. thanks. |
Brilliant! Thanks so much. I thought this might be an issue at the lower levels. I'm going to post this over to the AWS Amplify team so they can see the potential issue and then go back to using just core. Do you think it's safe to leave the community version linked so it's ready to go later? |
@rogueturnip Yeah, it would be fine. Please close the issue if you think that the case is solved. thanks. |
I don't have my iOS environment available until monday (unless I get time to go in and use it) so I'll test on Monday and close then. Thanks again for your help. |
Looks all good using the old core. Thanks! |
@krizzu the link in your comment is returning a 404. |
Is there any strategy to avoid this behavior? I have the following problem: one of my dependencies is using the core async storage (aws amplify), another the community version (react-native-permissions). In my code I can decide which to use, but thats impossible for dependencies. How can I ensure consistency? |
@mllrmat I can think of using babel module resolve plugin for that. |
@krizzu what would the config look like if I want to replace the core module with the community one? I tried this:
But it seams to have no effect. |
@mllrmat It's because you're not using |
Maybe I'm just being very naive - very likely as I'm a very green React developer - but I've struggled for about 5 hours debugging the AWS Amplify library trying to figure out why my logged-in state was not being persisted, and turns out it's not a bug with AWS Amplify or my code, it's because of this incompatibility between the deprecated AsyncStorage and the new one recommended to us, and I didn't read any warnings indicating this (https://facebook.github.io/react-native/docs/asyncstorage just says use this community version instead, seems pretty definitive). This is deeply frustrating as I don't think it's reasonable for React developers to know all implementation details of packages they depend on and so know which version of AsyncStorage to use - I just used the new one recommended in the official React Native docs and got seriously burnt. Is there a flag in the new community AsyncStorage version to write to a different file and so avoid this race condition? If there is then I could avoid having to tightly couple my AsyncStorage version I'm using to the one used by one of the libraries I'm using. Plus as @mllrmat points out, if competing dependencies use different AsyncStorage versions life becomes even more complicated again. Please advise. Perhaps I'm just being very naive and precious here, but after a weekend of debugging another library's code and finding the root cause to be this - which seems very avoidable and predictable - I'd like to suggest an improvement here and at least provide an option for both the deprecated and community versions to be able to play nicely together. |
Hey @danrivett , Due to React Native core getting slimmer, some packages that were previously bundled together with React Native were moved out to separate repos (AsyncStorage included). In order to give some transition time, the deprecation warning was used. Some devs moved immediately to use AsyncStorage from Community org, while others decided to wait with that decision. For example, apmplify-js uses built-in version. This is a situation I mentioned in my comment above. Unfortunately, we don't have the feature to change save destination file in place (I'm open for help with implementing this). I can safely say that you're good to use deprecated Async Storage, for now, just ignore the warning. |
@krizzu I have the same situation where we use aws' amplify-js and this uses the old one, that we absolutely need to revert back to 1.2.4 to navigate around inconsistency in persisting data? I encountered the issue with v.1.6.1 that values are not reliably persisted. After restarts, the data is gone leading to quite some troubles within the app. My setup is:
|
@taschik |
@krizzu How do you mean this? Remove the package completely? |
@taschik If you can't change what version of Async Storage your dependencies are using, I advise to not use this package for now - to avoid race conditions and possible loss of data. |
ah get it ok. Thanks a lot I reverted to importing |
Yeah we just ran into this issue and it was a tough one to track down as it was inconsistent behaviour. Should a warning be added to the readme around this as it is not obvious that you can't mix and match. |
I'm hoping someone could answer my question about a problem I'm seeing.
I'm using aws-amplify which is still using the old react-native core version of asyncstorage. I've moved my app over to using the react-native-community version. When I look at the storage while the app is running both are populating the asyncstorage correctly but when I restart the app only the data from my app using the react-native-community version is still there.
I've tried many things to try to fix this but to no luck. What I'm wondering is if there is a chance of conflict between the two if a module is still using the old version.
Thanks!
The text was updated successfully, but these errors were encountered: