You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browser version: Google Chrome Version 80.0.3987.163 (Official Build) (64-bit)
Firebase SDK version: 7.14.1
Firebase Product: Firestore
[REQUIRED] Describe the problem
Callback for realtime updates works wrong. If there is an open subscription for doc and I'm opening new subscription for collection with limit, callback of onSnapshot work twice. Instead it should work only once.
Then subscribe to the collection ordered by createdAtUnix desc and set limit 1.
db.collection('countries').orderBy('createdAtUnix','desc').limit(1).onSnapshot((snapshot)=>{// this work twice, first call's snapshot contains doc of subscription describe upperconsole.log('realtime collection snapshot');});
Works ok
Click on yellow button (subscribe to collection), onSnapshot work once.
Click on red button (reset subscriptions).
Works wrong
Click on green button. (Subscribe to a single doc).
Click on yellow button (subscribe to collection) callback passed to onSnapshot work twice.
The text was updated successfully, but these errors were encountered:
I believe the behavior you are seeing is as expected. When you are fetch countries/${docId} we store it in the local cache. We will then use the cached document for all new queries. In your case, countries/${docId} is the document that best matches the limit() query locally - at least at first. The backend then tells us that there is a different document that actually sorts higher and we raise another snapshot with the server's results.
To illustrate with an example:
You fetch db.collection('countries/a') with { createdAtUnix: 10 }. This is now in the cache.
You fetch db.collection('countries').orderBy('createdAtUnix', 'desc') .limit(1)
The SDK computes a list of results from cache. The only document that matches is countries/a.
The backend tells us about countries/b with {createdAtUnix: 20}. We store it in cache.
The SDK now recomputes the result for the limit query .countries/b is now the first ordered result and we raise another snapshot.
You can filter results from cache by looking at the fromCache metadata flag. This allows you to only react to change events that are synchronized with the backend.
[REQUIRED] Describe the problem
Callback for realtime updates works wrong. If there is an open subscription for doc and I'm opening new subscription for collection with limit, callback of
onSnapshot
work twice. Instead it should work only once.Steps to reproduce:
Create collection countries.
Seed some data.
Subscribe to the last doc ordered by
createdAtUnix
desc from countries collection.Then subscribe to the collection ordered by createdAtUnix desc and set limit 1.
Relevant Code:
https://jsfiddle.net/vazgentigranich/9abz6suk/175/
Works ok
Click on yellow button (subscribe to collection), onSnapshot work once.
Click on red button (reset subscriptions).
Works wrong
Click on green button. (Subscribe to a single doc).
Click on yellow button (subscribe to collection) callback passed to onSnapshot work twice.
The text was updated successfully, but these errors were encountered: