fix: defer query refresh until pending offline transactions complete#1390
Merged
fix: defer query refresh until pending offline transactions complete#1390
Conversation
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-browser-wa-sqlite-persisted-collection
@tanstack/db-capacitor-sqlite-persisted-collection
@tanstack/db-cloudflare-do-sqlite-persisted-collection
@tanstack/db-electron-sqlite-persisted-collection
@tanstack/db-expo-sqlite-persisted-collection
@tanstack/db-ivm
@tanstack/db-node-sqlite-persisted-collection
@tanstack/db-react-native-sqlite-persisted-collection
@tanstack/db-sqlite-persisted-collection-core
@tanstack/db-tauri-sqlite-persisted-collection
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: +15 B (+0.01%) Total Size: 111 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 4.23 kB ℹ️ View Unchanged
|
41f3a33 to
d33025d
Compare
…h race Adds an integration test that reproduces the race condition where a query-backed collection reverts to stale server state when coming back online with pending offline transactions. The queryFn refetch returns pre-mutation data before the offline transaction reaches the server, and when the transaction completes the optimistic state is cleaned up with nothing to replace it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The e2e tests import @tanstack/offline-transactions which may not be built during the default `pnpm test` CI step. Adds a vitest.config.ts that excludes the e2e directory from the default run while preserving typecheck on the regular test files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9d4914b to
0d389b1
Compare
The new e2e test imports @tanstack/offline-transactions, which needs to be built before the query e2e tests run. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When coming back online with pending offline transactions, query-backed collections would refetch stale server state before the mutations reached the server. After the transaction completed, the optimistic state was cleaned up but syncedData still had the stale data, causing items to temporarily disappear. The fix adds a `deferDataRefresh` property on Collection that the offline executor sets while replaying pending transactions. The query-db-collection checks this barrier in handleQueryResult: stale results are skipped, and a fresh refetch is triggered once the barrier resolves. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
samwillis
approved these changes
Mar 19, 2026
Collaborator
samwillis
left a comment
There was a problem hiding this comment.
just needs a changeset
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1323
Summary
deferDataRefreshbarrier on the Collection that the offline executor sets when replaying pending transactions, and that the query collection checks before processing query resultsTest plan
offline-refresh.e2e.test.tsreproduces the bug (fails without fix, passes with fix)query.test.tstests pass (170/170)offline-e2e.test.tstests pass🤖 Generated with Claude Code