Firestore - collectionChanges function not emitting empty array when not elements present in queried collection
Angular: 13.3.11
Firebase: 9.8.4
AngularFire: 7.4.1
Other (e.g. Ionic/Cordova, Node, browser, operating system): Node: 14.19.0 Maxc OS: 12.3.1 Chrome (latest)
How to reproduce these conditions
const elements = [1,2,3];
const surveyReferencesQuery = query( collection( this.afs, 'surveyReferences' ) as CollectionReference<ISurveyReference>, where('companyId', 'in', elements) );
return collectionChanges( surveyReferencesQuery ).pipe( tap((c) => console.log( 'collectionChanges', c.map((s) => [ s.type, s.doc.id, s.doc.data(), ]) ) ) );
Expected behavior
Should emit empty array
Actual behavior
Not emitting anything until documents in collection
This issue does not seem to follow the issue template. Make sure you provide all the required information.
Hi @alejandrogkl, the issue you are reporting here is caused by an issue in rxfire I logged quite some time ago. Very annoying and definitely a nasty bug in my opinion, as it broke my application.
My current workaround is to use patch-package (link to GitHub repo) and apply the following patch (this works for rxfire 6.0.3:
diff --git a/node_modules/rxfire/firestore/index.esm.js b/node_modules/rxfire/firestore/index.esm.js
index 0082e3d..f8e2f63 100644
--- a/node_modules/rxfire/firestore/index.esm.js
+++ b/node_modules/rxfire/firestore/index.esm.js
@@ -249,7 +249,7 @@ function collectionChanges(query, options) {
});
}
return docChanges;
- }), filterEvents(options.events || ALL_EVENTS), filterEmptyUnlessFirst());
+ }), filterEmptyUnlessFirst());
}
/**
* Return a stream of document snapshots on a query. These results are in sort order.
Still have this issue. Not fixed yet?
No fix that I'm aware of in any case, I've been tracking this issue but still rocking my custom patch (as seen in above comment) until now. Looks like either no one else is experiencing this, or not noticing that they are ;)