Skip to content
Source
Sign inSign up
TanStack/db

[repro] synced data not appearing in derived collection during pending optimistic mutation (issue #1017) #1166

Closedclaude[bot](GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromai/issue-1017-reproopened

Showing 1 changed file with 106 additions and 0 deletions.

x
0 of 1 viewed, 1 left
106 additions and 0 deletionspackages/db/tests/query/live-query-collection.test.tsModified
View file
@@ -15,6 +15,7 @@
mockSyncCollectionOptionsNoInitialState,
} from '../utils.js'
import { createDeferred } from '../../src/deferred'
+import { createOptimisticAction } from '../../src/optimistic-action.js'
import type { ChangeMessage, LoadSubsetOptions } from '../../src/types.js'
​
// Sample user type for tests
@@ -1072,6 +1073,111 @@
expect(liveTodo?.completed).toBe(true)
+​
+ describe(`synced data visibility during pending optimistic mutations`, () => {
+ it(`shows synced data in derived collection while optimistic action mutation is pending`, async () => {
+ // This test verifies that synced data from the source collection appears
+ // in the derived live query collection even when there is a pending
+ // optimistic mutation on that derived collection.
+ //
+ // Uses createOptimisticAction with a controlled mutationFn to ensure
+ // the optimistic mutation stays pending while we sync new data.
+​
+ type Item = { id: string; value: string }
+​
+ let syncBegin!: () => void