snapshotChanges().take(1).toPromise() returns partial and inconsistent results
See original GitHub issueVersion info
Angular: “@angular/common”: “5.0.3”,
Firebase: “firebase”: “^4.11.0”,
AngularFire: “angularfire2”: “^5.0.0-rc.6”,
Other (e.g. Ionic/Cordova, Node, browser, operating system): “ionic-angular”: “3.9.2”,
How to reproduce these conditions
Failing test unit, Plunkr, or JSFiddle demonstrating the problem
Steps to set up and reproduce
When using angularfire api, the results of the query on the same data can be sometimes: none, one or all:
angularFire.collection(X).where(Y).snapshotChanges().take(1).toPromise().then(...) --> returns inconsistent results
When using firebase api on the same query with the same data, all the results are returned consistently.
firebase.firestore().collection(X).where(Y).get().then(...) --> always returns all results
Expected behavior
It is expected that the .snapshotChanges().take(1).toPromise() on the angularfire query api will give the same results as get().then() on firestore query api.
Actual behavior
The results of the query over the same data is inconsistent. Sometimes it returns no results / one results / all results.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (7 by maintainers)
No, get() replaces the need for take(1) and allows an optional argument allowing you to control whether the results come from the server or cache.
This behavior is not erroneous. It’s your local cache firing the first emission per design of the JS SDK. You do want the user to see something if their network is not available right?
We’re thinking of allowing an argument to value/snapshotChanges() allowing you to control the source (or at least include metadata so you can filter) but it would require a breaking change, so we can’t do it until 6.0. We’ll likely add it in a new Observable but have to consider the design.
On Sun, Sep 2, 2018, 8:55 PM Kyle Cordes notifications@github.com wrote:
I’m having a problem with get(), as when I’m using it in combination with Angular Universal to prerender pages, it takes around one minute per page to complete. I suspect there might be a problem with a promise that doesn’t resolve, both valueChanges() and snapshotChanges() work perfectly, but only give the cached results, as my prerendering script only waits for the first emission.