FirebaseExtended / FirebaseExtended/rxfire

collectionChanges is firing for every element on a single deletion

Open
#75 3 comments 0 reactions 1 assignee Claimed by @davideast View on GitHub
Dominant language
TypeScript
Stars
149
Forks
50
PR merge metrics
No merged PRs in 30d

Description

I have AngularFire/RxFire code similar to the following:

```javascript
collectionChanges(
collection(this.firestore, "col1/doc1/col2"))
.subscribe(changes => {
console.log('RxFire changes', changes);
});
```
This generally works: When the page loads, I get `added` events for every document in the collection. When a document changes, a single `modified` event fires. However, when a document is deleted, the next change batch includes a `removed` event (good) and also a `modified` event for every other element in the collection (bad). 🤔

Any idea why these extra modify events are happening + how to avoid all the extra reads? or is this all from the cache?

I've verified there's no actual change to the other documents in the collection. A single modified change mentions oldIndex and newIndex so I wonder if it's maybe trying to update the index of every element, but there isn't a sort order so any index is undefined anyways.

----

If it's helpful, as a test I tried the equivalent Firebase code:

```javascript
const q = query(collection(this.firestore, "collection1/doc1/collection2"));

onSnapshot(q, (snapshot) => {
const docs = snapshot.docChanges();
console.log("Changes received", docs);
});
```

This works as expected and only fires one `removed` event, which is why I think the bug is in RxFire.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.