Skip to content

Commit b29420b

Browse files
authored
rollback batching of transaction commit (#87)
1 parent baeca80 commit b29420b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.changeset/some-bears-sniff.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+
fix a bug where query results would not correctly update

packages/db/src/transactions.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { batch } from "@tanstack/store"
21
import { createDeferred } from "./deferred"
32
import type { Deferred } from "./deferred"
43
import type {
@@ -179,10 +178,8 @@ export class Transaction {
179178
try {
180179
await this.mutationFn({ transaction: this })
181180

182-
batch(() => {
183-
this.setState(`completed`)
184-
this.touchCollection()
185-
})
181+
this.setState(`completed`)
182+
this.touchCollection()
186183

187184
this.isPersisted.resolve(this)
188185
} catch (error) {

packages/db/tests/collection-subscribe-changes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ describe(`Collection.subscribeChanges`, () => {
399399
await tx.isPersisted.promise
400400

401401
// Verify synced update was emitted
402-
expect(callback).toHaveBeenCalledTimes(0)
402+
expect(callback).toHaveBeenCalledTimes(2) // FIXME: this should ideally be 0 - we currently see a delete and an insert
403403
// This is called 1 time when the mutationFn call returns
404404
// and the optimistic state is dropped and the synced state applied.
405405
callback.mockReset()
@@ -556,7 +556,7 @@ describe(`Collection.subscribeChanges`, () => {
556556
await waitForChanges()
557557

558558
// Verify synced update was emitted
559-
expect(callback).toHaveBeenCalledTimes(0)
559+
expect(callback).toHaveBeenCalledTimes(2) // FIXME: this should ideally be 0 - we currently see a delete and an insert
560560
// This is called when the mutationFn returns and
561561
// the optimistic state is dropped and synced state is
562562
// applied.

0 commit comments

Comments
 (0)