-
Notifications
You must be signed in to change notification settings - Fork 884
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
Firestore offline persistence not working on react native #436
Comments
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight. |
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information. |
You might want to use https://rnfirebase.io instead. It works really well. |
Hi, Thanks, sadly that library requires manual linking to native code for ios / android, which I think it goes against the "write once, run everywhere" mentality that react native is trying to achieve. |
You can just eject from expo and still use the expo sdk if you wanna use its tools. And the manual linking is required, its a small caveat to the react native process. You link then you write JS code once that runs on Android or iOS. |
The best solution would be to enable offline persistance within react-native. Are there any structural problems to achieve this or should we consider that it's only a matter of time ? |
Hi All, But it throws an exception when i want to enable offline-persistence. See the given code in my repo to test it. Can anyone name a working offline-persistence for firestore with react-native and expo? |
According to the docs:
https://firebase.google.com/docs/firestore/manage-data/enable-offline Can you try not calling |
It's been a while since there has been any activity on this issue, so I am going to close it. While we want to support using Firestore everywhere in a flexible manner, right now our only recommended usage method for React Native is through Please give that library a try, and raise issues on that repository if persistence does not work. |
😢 @samtstern Would be really great if there would be way, or at least some workaround how to make persistence work without need to use native modules. |
Thanks @jurosh I only got responses that did not address the issue. I think @jurosh explained my point really well. |
I'm no expert in react-native, but you're welcome to try making changes here: This is the logic that determines whether or we allow offline persistence on the platform. Just as a test you could force that method to return As I understand it though with a brief search, react-native does not support IndexedDB, which is why that function returns You might also try to find something to polyfill IndexedDB, similar to IndexedDBShim though that makes no mention of AsyncStorage support so I'm not hopeful for that particular one. So unless react-native actually supports IndexedDB and our test is just wrong, our advice stands: if you want offline persistence you have to use react-native-firebase. |
not expert with react native.. On iOS if react-native using webview where IndexedDB not implemented so firestore persistence will not work. again don't know much about react native but i think you should give a try using this; share with us the result :) |
I tried multiple times to enable persistence on react native but failing each time.. I tried doing it via settings like The weirdest thing about this is if I run my app offline, all works well, images loading instantly, everything is kept as it was from the last launch, but as soon as I relaunch with the wifi on, all the data is being loaded from the back end and it takes sometimes 5s for the image to appear.. Its a very big issue for me and I have no idea how to solve |
it works with invertase / react-native-firebase - unfortunately
incompatible with expo
Le mar. 26 juin 2018 à 20:35, Gvidas M. <notifications@github.com> a écrit :
… I tried multiple times to enable persistence on react native but failing
each time.. I tried doing it via settings like firebase.firestore().settings({
persistence: true }) but that wont work as well. The weirdest thing about
this is if I run my app offline, all works well, images loading instantly,
everything is kept as it was from the last launch, but as soon as I
relaunch with the wifi on, all the data is being loaded from the back end
and it takes sometimes 5s for the image to appear.. Its a very big issue
for me and I have no idea how to solve
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#436 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMCgW5GgiqHY0fdN7_FFebAvcL3bO2hAks5uAn7pgaJpZM4RdzV4>
.
|
@philohelp I am not using expo |
https://github.com/sunnylqm/react-native-storage can't this be used to plug into the local storage that firebase is using? shouldn't be hard to implement that library to create a solution that works for expo.. |
Is there any plan to add offline persistence for Expo? |
@nandorojo We don't currently have plans to invest in making our Web SDK offline support work in React Native. Would it be possible to use the native (Android / iOS) Firestore SDKs instead? I believe Expo supports that to some degree now. https://blog.expo.io/using-firebase-in-expo-e13844061832 |
Hey @mikelehen, thanks for getting back to me. The article you attached is for detached Expo projects only unfortunately, so it doesn't work with managed Expo projects. I understand there's no plan for this now, but I think it would be amazing if you decided to add support for RN offline. Many apps are moving towards RN (above all, Expo) and offline support is a central draw of using Firestore. I believe JS libraries like redux-persist use From the article you sent:
Really hoping this gets added to plans for support. Thanks again for your help! |
My previous response on this topic still stands. React Native's Essentially, until it's possible to polyfill IndexedDB on top of React Native, there's no way we can support offline persistence there. |
Thanks for clarifying. While I'm not familiar with how IndexedDB works, if I could come up with an implementation for React Native, would offline persistence then be supported? |
@nandorojo Yes! It should just automatically work if IndexedDB was available (
|
I hesitate to share this because of how hacky it all seems, but I did manage to get Firestore persistence working in an Expo app with the firebase web SDK: https://gist.github.com/zwily/e9e97e0f9f523a72c24c7df01d889482 I wouldn't ship anything with that without a ton of testing (I've only done about an hour's worth). It does appear to be feasible though! |
I actually disabled firebase persistance and doing it all myself using realm local db. Its super fast and it acts like a bridge between your user and firebase db |
@SourceCipher Do you have an example of how to implement that? Do all firestore persistence features work? So far I've been storing all of my firestore data in redux, and using @zwily Thank you for passing along the gist, I'll give it a try tonight! |
@nandorojo Let me know how it goes. I haven't run into any problems while testing my app today, and it's nice having everything loading so quickly... |
@zwily Seems to work (with a slight lag). Will do more tests throughout the night to figure out if the lag is in my render code or not and if there are any bugs. This is great work. I’ll do what I can to make sure it’s ready for production. Also, is it worth adding a check for the react native platform in case the user is on expo web? |
@zwily Thank you SO much ! Working like a charm ! |
@zwily haha I was too quick to talk : On Android
|
I've had no issues on iOS and have been testing for about a week so far. I'll try it out on Android too. @bulby97 Would you mind describing the error a bit more? Did this happen immediately on app load? Does it keep the app from working? Is your |
I've tested @zwily's solution on Android and get the same error as @bulby97. It keeps the app from working at all. For now I'm trying |
@nandorojo @bulby97 @zwily We are actually using IndexedDbShim as our testing layer during development. While I certainly don't recommend that anyone should ship an actual app using this, it has been relatively reliable (other than the fact that is is a little on the slow side). See https://github.com/firebase/firebase-js-sdk/blob/3c8f85d0185e3305f0ba7790d46eebb8e9e78e62/packages/firestore/test/util/node_persistence.ts |
@schmidt-sebastian Thanks for the heads up! I'll test it out. For now, @zwily's solution seems to work on iOS, though I'm still testing speeds for it. Given the high levels of investment in react native/expo from the community, I hope that at some point the firebase team considers a similar pure-JS workaround for persistence on react native. |
@zwily Perhaps there is a better place to put these errors, but I got this randomly on iOS: Seems to be a SQLite error of sorts, not sure what the cause is. |
setting the autoIncrement to true but i can not figure out how to set it by override |
been following this thread for a year.. would love to see android implementation |
Same here. Does that hack support Android @zwily ? |
when enabling persistence I get an error on react native:
Error enabling offline storage. Falling back to storage disabled: FirebaseError: [code=unimplemented]: This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.
When reading https://firebase.google.com/docs/firestore/manage-data/enable-offline
I see:
Note: Offline persistence is supported only in Android, iOS, and web apps.
and
Important: For the web, offline persistence is an experimental feature that is supported only by the Chrome, Safari, and Firefox web browsers. Also, if a user opens multiple browser tabs that point to the same Cloud Firestore database, and offline persistence is enabled, Cloud Firestore will work correctly only in the first tab.
I assume that is the reason why that is not working on react native, if so, could you confirm. Is this in the pipeline?
The text was updated successfully, but these errors were encountered: