Skip to content

Commit 38d4505

Browse files
authored
If collection.update is called and nothing is changed, return a transaction instead of throwing (#174)
1 parent 0bb3323 commit 38d4505

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/pretty-otters-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tanstack/db": patch
3+
---
4+
5+
If collection.update is called and nothing is changed, return a transaction instead of throwing

packages/db/src/collection.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,13 @@ export class CollectionImpl<
10431043
})
10441044
.filter(Boolean) as Array<PendingMutation<T>>
10451045

1046-
// If no changes were made, return early
1046+
// If no changes were made, return an empty transaction early
10471047
if (mutations.length === 0) {
1048-
throw new Error(`No changes were made to any of the objects`)
1048+
const emptyTransaction = new Transaction({
1049+
mutationFn: async () => {},
1050+
})
1051+
emptyTransaction.commit()
1052+
return emptyTransaction
10491053
}
10501054

10511055
// If an ambient transaction exists, use it

0 commit comments

Comments
 (0)