angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.69k stars 2.19k forks source link

Multiple valueChange subscriptions for same collection leads to one subscription firing changes for another #2740

Open HadiAyoub opened 3 years ago

HadiAyoub commented 3 years ago

Version info

Angular: 10.0.9

Firebase: ^7.13.1

AngularFire: ^6.02

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

Create multiple valueChange subscriptions to the same collection (with a different query)

this.db.collection('/people/' + this.selectedPeopleId + '/messages', ref => ref.orderBy("createdDate").limitToLast(100)).valueChanges({idField: 'documentId'}).subscribe(messageUpdates => 

AND

this.db.collection('/people/' + this.selectedPeopleId + '/messages', ref => ref.where("type", ">", 0).limitToLast(100)).valueChanges({idField: 'documentId'}).subscribe(messageUpdates => 

In my case, I am unsubscribing from the second listener and recreating it with a different limitToLast value (though I'm unsure if that's necessary to reproduce)

Debug output

none

Expected behavior

Each valueChange listener should only fire results for itself

Actual behavior

the first listener is returning valueChanges that match the query for the second listener.

HadiAyoub commented 3 years ago

My gut feeling is this could be related to caching?

Can confirm, this is related to query caching. Seems like a bug, rather than intended behaviour as described here though: https://github.com/angular/angularfire/issues/2336

as the cached result is incorrect.

Benny739 commented 3 years ago

Same issue here. If you listen to a document directly, it does not even have to be the same collection. If you have multiple listeners and 1 listener gets an update all listeners will fire a "modified" event.

cm-cm-cm-cm commented 3 years ago

I have noticed this behavior as well

charliejlevine commented 3 years ago

+1