adriancarriger / angularfire2-offline

🔌 A simple wrapper for AngularFire2 to read and write to Firebase while offline, even after a complete refresh.
https://angularfire2-offline.firebaseapp.com/
MIT License
207 stars 48 forks source link

Network Error when using Ionic #52

Closed wbhob closed 7 years ago

wbhob commented 7 years ago

When I use this module with Ionic, I get this error:

GET https://*******.firebaseio.com/.lp?start=t&ser=62360009&cb=2&v=5 net::ERR_INTERNET_DISCONNECTED

This occurs when I don't have internet connection on load. Does anyone else have this issue? I am also unable to push on a firebase list when offline.

adriancarriger commented 7 years ago

Hi @wbhob, thanks for posting!

Errors

The ERR_INTERNET_DISCONNECTED error is normal while your app is offline. The Afo demo displays the same behavior. It would be awesome to get rid of the errors, but as far as I know removing the errors would require touching Firebase code (please let me know if this is possible).

Offline writes

You should be able to push to your angularfire2-offline list while offline. These pushes would only be reflected in your app, and they won't show up in other places such as the Firebase console or other apps that use the same Firebase database until the app in question goes back online. Feel free to test this with the demo. 👍

Questions

To help narrow down the issue, please answer these questions:

Thanks!

wbhob commented 7 years ago

So I think what happens is that the promises from push on lists and update on objects aren't being fired if you're offline, a functionality that my app depends on to make sure the data is saved before advancing to the next view.

Should I just move resolution code outside of the promise context for the time being?

adriancarriger commented 7 years ago

Turns out that an "offline write promises" feature is requested in issue #44. Would that solve your issue?

wbhob commented 7 years ago

It definitely would!

adriancarriger commented 7 years ago

Offline write promises now work in version 4.2.1! 🎉

Demo make sure to look at the console (with Code)

Usage

const promise = this.afoDatabase.object('car').update({maxSpeed: 100});
promise.offline.then(() => console.log('offline write complete!'));
wbhob commented 7 years ago

Incredible, thanks so so much!