Patch Changes
-
Improve runtime error message and documentation when
useLiveSuspenseQueryreceivesundefinedfrom query callback. (#860)Following TanStack Query's
useSuspenseQuerydesign,useLiveSuspenseQueryintentionally does not support disabled queries (when callback returnsundefinedornull). This maintains the type guarantee thatdatais alwaysT(notT | undefined), which is a core benefit of using Suspense.What changed:
-
Improved runtime error message with clear guidance:
useLiveSuspenseQuery does not support disabled queries (callback returned undefined/null).
The Suspense pattern requires data to always be defined (T, not T | undefined).
Solutions:- Use conditional rendering - don't render the component until the condition is met.
- Use useLiveQuery instead, which supports disabled queries with the 'isEnabled' flag.
-
Enhanced JSDoc documentation with detailed
@remarkssection explaining the design decision, showing both incorrect (❌) and correct (✅) patterns
Why this matters:
// ❌ This pattern doesn't work with Suspense queries: const { data } = useLiveSuspenseQuery( (q) => userId ? q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne() : undefined, [userId] ) // ✅ Instead, use conditional rendering: function UserProfile({ userId }: { userId: string }) { const { data } = useLiveSuspenseQuery( (q) => q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne(), [userId] ) return <div>{data.name}</div> // data is guaranteed non-undefined } function App({ userId }: { userId?: string }) { if (!userId) return <div>No user selected</div> return <UserProfile userId={userId} /> } // ✅ Or use useLiveQuery for conditional queries: const { data, isEnabled } = useLiveQuery( (q) => userId ? q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne() : undefined, [userId] )
This aligns with TanStack Query's philosophy where Suspense queries prioritize type safety and proper component composition over flexibility.
-
-
Updated dependencies [
f795a67,d542667,6503c09,b1cc4a7]:- @tanstack/db@0.5.17