Skip to content
Source
Sign inSign up
TanStack/db

Failing repro: loadSubset resolves & live query marks ready while synced rows are parked behind a persisting transaction #1662

ClosedTomasGonzalez(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1662/headopened

Showing 1 changed file with 118 additions and 0 deletions.

x
0 of 1 viewed, 1 left
118 additions and 0 deletionspackages/db/tests/query/load-subset-persisting-deferral.test.tsAdded
View file
@@ -0,0 +1,118 @@
+import { describe, expect, it } from 'vitest'
+import { createCollection } from '../../src/collection/index.js'
+import { createLiveQueryCollection, eq } from '../../src/query/index.js'
+import { createTransaction } from '../../src/transactions'
+​
+// Reproduction for the on-demand `loadSubset` readiness bug.
+//
+// When any user transaction on a collection is in state `persisting`, a synced
+// transaction committed by `loadSubset` is parked by `commitPendingTransactions`
+// (src/collection/state.ts skips applying while `hasPersistingTransaction`), yet
+// the `loadSubset` promise still resolves and the live query still marks ready.
+// So `toArrayWhenReady()` resolves with an empty/stale result for rows that were
+// actually fetched and committed.
+//
+// The `loadSubset` below begins/writes/commits synchronously and then resolves —
+// exactly like @tanstack/electric-db-collection's subscribe handler does on a
+// `subset-end` control message, before its `requestSnapshot` promise resolves.
+​
+interface Row {
+ id: string
+ projectId: string
+ name: string
+}
+​
+const row1: Row = { id: `r1`, projectId: `p1`, name: `a` }
+const row2: Row = { id: `r2`, projectId: `p1`, name: `b` }
+​