fix(react-db): use collection.status instead of snapshot in useLiveSuspenseQuery to avoid infinite fallback loops#1427
Open
calcari wants to merge 1 commit intoTanStack:mainfrom
Open
fix(react-db): use collection.status instead of snapshot in useLiveSuspenseQuery to avoid infinite fallback loops#1427calcari wants to merge 1 commit intoTanStack:mainfrom
calcari wants to merge 1 commit intoTanStack:mainfrom
Conversation
…uspenseQuery (TanStack#1418) result.status can be stale because it comes from the useSyncExternalStore snapshot, while result.collection is a live mutable reference. This may cause an inconsistent render where: - result.status === "loading" - result.collection.status === "ready" Switching to result.collection.status ensures Suspense uses the latest state and prevents infinite fallback loops. Changes: - introduce collectionStatus variable - replace all status checks (loading, idle, error, ready) with collectionStatus - move isEnabled check before accessing result.collection
kevin-dp
approved these changes
Mar 30, 2026
Contributor
kevin-dp
left a comment
There was a problem hiding this comment.
Thanks for catching and fixing this!
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
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 #1418
In useLiveSuspenseQuery.ts
result.statuscomes from the snapshot in useLiveQuery.tsresult.collection.statusis a live referenceThis may cause an inconsistent render where:
The react documentation says "It’s not recommended to suspend a render based on a store value returned by useSyncExternalStore." so reading the fresh status from the mutable collection seems correct here.
Switching to result.collection.status ensures Suspense uses the latest state and prevents infinite fallback loops.
Demo
I could not add a reliable RTL/jsdom test for this React 19 Suspense scenario, as it appears to hit the limitation discussed in testing-library/react-testing-library#1375.
As a fallback, I added a small demo showing the fix in action:
StackBlitz
🎯 Changes
✅ Checklist
pnpm test.🚀 Release Impact