[repro] synced data not appearing in derived collection during pending optimistic mutation (issue #1017) #1166
main fromai/issue-1017-repro·opened Summary#
Adds a reproduction test for issue #1017: Synced data does not appear in a derived (live query) collection while there is a pending optimistic mutation on that derived collection.
What the test asserts#
The test validates that synced data from a source collection should appear in derived collections immediately, regardless of whether there are pending optimistic mutations.
Test flow:
- Creates a source collection with controllable sync
- Creates a derived collection via
createLiveQueryCollection(simple passthrough) - Uses
createOptimisticActionto insert an item with a pending mutation - While mutation is pending, syncs a NEW item into the source collection
- Asserts both items should be visible in the derived collection
How to run#
pnpm --filter "@tanstack/db" test -- tests/query/live-query-collection.test.ts -t "synced data visibility"
Observed failure#
AssertionError: expected false to be true
❯ tests/query/live-query-collection.test.ts:1170:41
expect(derived.has(`synced-1`)).toBe(true)
The synced item (synced-1) is invisible in the derived collection while the optimistic mutation is pending, confirming the bug.
Related#
Fixes #1017
- 1
More templates
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@1166@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@1166@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@1166@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@1166@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@1166@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1166@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@1166@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@1166@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1166@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@1166@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@1166@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1166@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@1166commit:
883f4e2Size Change: 0 B
Total Size: 90.8 kB
compressed-size-action::db-package-sizeℹ️ View Unchanged
Filename Size ./packages/db/dist/esm/collection/change-events.js1.39 kB ./packages/db/dist/esm/collection/changes.js1.19 kB ./packages/db/dist/esm/collection/events.js388 B ./packages/db/dist/esm/collection/index.js3.32 kB ./packages/db/dist/esm/collection/indexes.js1.1 kB ./packages/db/dist/esm/collection/lifecycle.js1.67 kB ./packages/db/dist/esm/collection/mutations.js2.34 kB ./packages/db/dist/esm/collection/state.js3.49 kB ./packages/db/dist/esm/collection/subscription.js3.62 kB ./packages/db/dist/esm/collection/sync.js2.41 kB ./packages/db/dist/esm/deferred.js207 B ./packages/db/dist/esm/errors.js4.7 kB ./packages/db/dist/esm/event-emitter.js748 B ./packages/db/dist/esm/index.js2.69 kB ./packages/db/dist/esm/indexes/auto-index.js742 B ./packages/db/dist/esm/indexes/base-index.js766 B ./packages/db/dist/esm/indexes/btree-index.js1.93 kB ./packages/db/dist/esm/indexes/lazy-index.js1.1 kB ./packages/db/dist/esm/indexes/reverse-index.js513 B ./packages/db/dist/esm/local-only.js837 B ./packages/db/dist/esm/local-storage.js2.1 kB ./packages/db/dist/esm/optimistic-action.js359 B ./packages/db/dist/esm/paced-mutations.js496 B ./packages/db/dist/esm/proxy.js3.75 kB ./packages/db/dist/esm/query/builder/functions.js733 B ./packages/db/dist/esm/query/builder/index.js4.08 kB ./packages/db/dist/esm/query/builder/ref-proxy.js1.05 kB ./packages/db/dist/esm/query/compiler/evaluators.js1.42 kB ./packages/db/dist/esm/query/compiler/expressions.js430 B ./packages/db/dist/esm/query/compiler/group-by.js1.81 kB ./packages/db/dist/esm/query/compiler/index.js1.96 kB ./packages/db/dist/esm/query/compiler/joins.js2 kB ./packages/db/dist/esm/query/compiler/order-by.js1.45 kB ./packages/db/dist/esm/query/compiler/select.js1.06 kB ./packages/db/dist/esm/query/expression-helpers.js1.43 kB ./packages/db/dist/esm/query/ir.js673 B ./packages/db/dist/esm/query/live-query-collection.js360 B ./packages/db/dist/esm/query/live/collection-config-builder.js5.42 kB ./packages/db/dist/esm/query/live/collection-registry.js264 B ./packages/db/dist/esm/query/live/collection-subscriber.js1.93 kB ./packages/db/dist/esm/query/live/internal.js145 B ./packages/db/dist/esm/query/optimizer.js2.56 kB ./packages/db/dist/esm/query/predicate-utils.js2.97 kB ./packages/db/dist/esm/query/subset-dedupe.js921 B ./packages/db/dist/esm/scheduler.js1.3 kB ./packages/db/dist/esm/SortedMap.js1.3 kB ./packages/db/dist/esm/strategies/debounceStrategy.js247 B ./packages/db/dist/esm/strategies/queueStrategy.js428 B ./packages/db/dist/esm/strategies/throttleStrategy.js246 B ./packages/db/dist/esm/transactions.js2.9 kB ./packages/db/dist/esm/utils.js924 B ./packages/db/dist/esm/utils/browser-polyfills.js304 B ./packages/db/dist/esm/utils/btree.js5.61 kB ./packages/db/dist/esm/utils/comparison.js852 B ./packages/db/dist/esm/utils/cursor.js457 B ./packages/db/dist/esm/utils/index-optimization.js1.51 kB ./packages/db/dist/esm/utils/type-guards.js157 B Size Change: 0 B
Total Size: 3.7 kB
compressed-size-action::react-db-package-sizeℹ️ View Unchanged
Filename Size ./packages/react-db/dist/esm/index.js225 B ./packages/react-db/dist/esm/useLiveInfiniteQuery.js1.17 kB ./packages/react-db/dist/esm/useLiveQuery.js1.34 kB ./packages/react-db/dist/esm/useLiveSuspenseQuery.js559 B ./packages/react-db/dist/esm/usePacedMutations.js401 B Closing after the later #1017 loss audit. This reproduction asserts immediate derived publication while an optimistic mutation is pending, but the follow-up investigation found that bypassing the whole-transaction queue can expose temporary/server-key duplicates and violate atomicity. The remaining policy and design work is tracked in RFC #1625 rather than as this standalone fix contract.
KyleAMathews(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
⚠️ No Changeset found#
Latest commit: 883f4e23c86e1a582f7e3df53d9130974ea31ab9
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR