Angularfire: Offline first behavior (Serve cached datas first)

Created on 10 Oct 2017  路  5Comments  路  Source: angular/angularfire

Version info

Angular: 4.4.3
Firebase: 4.5.0
AngularFire: 5.0.0-rc.2
Ionic: 3.7.1

How to reproduce these conditions

Steps to set up and reproduce

Make any query to Firestore

this.db.collection<HeroServerData>('heroes').valueChanges();

Expected behavior

The Observable should emit first the local datas then a second time when the Firestore query is back. An offline first behavior basically.

Actual behavior

The Observable seems to wait for the server response. If none received, use the local datas.

It's hard to create a plunkr for this. Hope it will be clear enough.
Thanks

Most helpful comment

I'll create the issue. 馃槃

All 5 comments

Looking into the code and I think the issue lies in the firebase-js-sdk so you better post the issue there https://github.com/firebase/firebase-js-sdk

This issue seems to be related indeed https://github.com/firebase/firebase-js-sdk/issues/17

That issue is for the Realtime DB, but you need it for the Firestore DB. They are referring to the new Firestore DB as a solution for offline first, but they will end up with the same issue as you and me.

Either firebase needs to modify the js sdk so it will use data from cache (IndexDB) first and sync it in the background with the server or AngularFire needs to make the wrapper use the fromCache method instead.

I see. I don't have time right now so feel free to create the issue.

I'll create the issue. 馃槃

Was this page helpful?
0 / 5 - 0 ratings