question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

snapshotChanges().take(1).toPromise() returns partial and inconsistent results

See original GitHub issue

Version 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:closed
  • Created 5 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesdanielscommented, Sep 3, 2018

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:

@jamesdaniels https://github.com/jamesdaniels Doe get() make it possible to retrieve the first “real” result, and then further updates on there, without ever getting the erroneous partial result at the beginning?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/1552#issuecomment-417993778, or mute the thread https://github.com/notifications/unsubscribe-auth/AACvrxD-RQznTAUIDta9f3KDN5WhgVnnks5uXKgTgaJpZM4TMafV .

0reactions
MvRemmerdencommented, Feb 4, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Any workaround for this method without convert ...
A simple solution would be, in the getServer() method to convert the Observable to Promise, using toPromise() and returning this value
Read more >
property 'collection' does not exist on type 'firestore' - You.com
I use NS7 with Angular and my import looks like this : _import { firebase } from "@nativescript/firebase";_ firestore.init(…) works with no errors...
Read more >
extended-angular-firestore - UNPKG
observable to transform into Observable using Observable.from().\n *\n * This class is rarely used directly and should be created from the AngularFirestore ...
Read more >
Advanced Firestore Usage Guide with Angular - Fireship
A variety of tips and snippets that make AngularFire v5 and Firestore easier to use.
Read more >
Thread: Changeset Extraction v7.0 (was logical changeset ...
New output plugin interface with one _PG_output_plugin_init dlsym()ed function filling out the callbacks. * Renaming of the init and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found