Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/fix-array-iteration-proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@tanstack/db": patch
---

Fix change tracking for array items accessed via iteration methods (find, forEach, for...of, etc.)

Previously, modifications to array items retrieved via iteration methods were not tracked by the change proxy because these methods returned raw array elements instead of proxied versions. This caused `getChanges()` to return an empty object, which in turn caused `createOptimisticAction`'s `mutationFn` to never be called when using patterns like:

```ts
collection.update(id, (draft) => {
const item = draft.items.find((x) => x.id === targetId)
if (item) {
item.value = newValue // This change was not tracked!
}
})
```

The fix adds proxy handling for array iteration methods similar to how Map/Set iteration is already handled, ensuring that callbacks receive proxied elements and returned elements are properly proxied.

Also refactors proxy.ts for improved readability by extracting helper functions and hoisting constants to module scope.
Loading
Loading