diff --git a/src/firestore/collection/changes.ts b/src/firestore/collection/changes.ts index dfa415bd0..f02260539 100644 --- a/src/firestore/collection/changes.ts +++ b/src/firestore/collection/changes.ts @@ -61,17 +61,21 @@ export function combineChange(combined: DocumentChange[], change: Document } break; case 'modified': - // When an item changes position we first remove it - // and then add it's new position - if(change.oldIndex !== change.newIndex) { - combined.splice(change.oldIndex, 1); - combined.splice(change.newIndex, 0, change); - } else { - combined.splice(change.newIndex, 1, change); + if (combined[change.oldIndex] == null || combined[change.oldIndex].doc.id == change.doc.id) { + // When an item changes position we first remove it + // and then add it's new position + if(change.oldIndex !== change.newIndex) { + combined.splice(change.oldIndex, 1); + combined.splice(change.newIndex, 0, change); + } else { + combined.splice(change.newIndex, 1, change); + } } break; case 'removed': - combined.splice(change.oldIndex, 1); + if (combined[change.oldIndex] && combined[change.oldIndex].doc.id == change.doc.id) { + combined.splice(change.oldIndex, 1); + } break; } return combined;