-
Notifications
You must be signed in to change notification settings - Fork 2.2k
snapshotChanges().take(1).toPromise() returns partial and inconsistent results #1552
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
Comments
This is due to the mechanics explained in #1405. We plan on changing to a cold observable emission soon. Read and follow that issue for updates. |
I've experienced an interesting variation of this. I have a collection query with snapshotChanges() which always emits twice. First it emits just a single result (one document), then a moment later emits its actual correct result. I'm still investigating at what layer this happens etc.; but it seems worth a mention as it may be related to this earlier issue. |
@kylecordes the first emission is your cached results, the second is presumably the update from the server. |
@jamesdaniels @davideast It would be much preferable to have programmatic control (or at least visibility) on this. As we try to create visual polish by running animations as the data changes, this double delivery of the data causes exaggerated visual disruption. Yet there seems to be no straightforward path to postprocess the observable and get good results; skip(1) doesn't work, because on an initial load there will only be a single emit. Of course, I could be missing some obvious workaround, perhaps with a bit more Rx manipulation I could discard the initial delivery only if it happens within some very short time bound (indicating it came from cash) or similar. Still, even such a workaround would be much worse than some explicit way to handle this. |
We just added a get() observable in rc.12. That should help.
Docs are pending but give it a shot in the meantime.
…On Fri, Aug 24, 2018, 9:11 PM Kyle Cordes ***@***.***> wrote:
@jamesdaniels <https://github.com/jamesdaniels> @davideast
<https://github.com/davideast> It would be much preferable to have
programmatic control (or at least visibility) on this. As we try to create
visual polish by running animations as the data changes, this double
delivery of the data causes exaggerated visual disruption.
Yet there seems to be no straightforward path to postprocess the
observable and get good results; skip(1) doesn't work, because on an
initial load there will only be a single emit. debounceTime() works, but
requires guessing a time delay, a guess likely to be wrong on varying
hardware and networks.
Of course, I could be missing some obvious workaround, perhaps with a bit
more Rx manipulation I could discard the initial delivery only if it
happens within some very short time bound (indicating it came from cash) or
similar. Still, even such a workaround would be much worse than some
explicit way to handle this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1552 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACvr0UlUNLqK8NdQzcDNGjMhDTaE895ks5uUM5zgaJpZM4TMafV>
.
|
@jamesdaniels Doe |
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 ***@***.***> 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
<#1552 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACvrxD-RQznTAUIDta9f3KDN5WhgVnnks5uXKgTgaJpZM4TMafV>
.
|
@jamesdaniels will the issue get updated once this parameter is implemented? |
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. |
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.
The text was updated successfully, but these errors were encountered: