diff --git a/packages/signaldb/src/SyncManager/getSnapshot.ts b/packages/signaldb/src/SyncManager/getSnapshot.ts index d884972f..f3d3d0c9 100644 --- a/packages/signaldb/src/SyncManager/getSnapshot.ts +++ b/packages/signaldb/src/SyncManager/getSnapshot.ts @@ -14,10 +14,21 @@ export default function getSnapshot, IdType>( if (data.items != null) return data.items const items = lastSnapshot || [] - data.changes.added.forEach(item => items.push(item)) + data.changes.added.forEach((item) => { + const index = items.findIndex(i => i.id === item.id) + if (index !== -1) { + items[index] = item + } else { + items.push(item) + } + }) data.changes.modified.forEach((item) => { const index = items.findIndex(i => i.id === item.id) - if (index !== -1) items[index] = item + if (index !== -1) { + items[index] = item + } else { + items.push(item) + } }) data.changes.removed.forEach((item) => { const index = items.findIndex(i => i.id === item.id)