-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(solid-query): prevent suspense trigger with pre-cached data #10053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(solid-query): prevent suspense trigger with pre-cached data #10053
Conversation
When using `refetchOnMount: false` with pre-cached data, the first `setQueryData` call would incorrectly trigger a Suspense fallback. This happened because the Proxy handler was calling `queryResource()` even when cached data was available. This fix ensures that: 1. The resource resolves immediately when data is already available, regardless of the `isLoading` state 2. The Proxy handler returns cached data directly when `isFetching` is false and data exists, avoiding unnecessary resource access Closes TanStack#9883
|
📝 WalkthroughWalkthroughFixes a bug where mutations with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When using
refetchOnMount: falsewith pre-cached data, the firstsetQueryDatacall would incorrectly trigger a Suspense fallback. This happened because the Proxy handler was callingqueryResource()even when cached data was available.This fix ensures that:
isLoadingstateisFetchingis false and data exists, avoiding unnecessary resource accessCloses #9883
🎯 Changes
useBaseQuery.ts (line 263): Added || observerResult.data !== undefined condition to resolve the resource immediately when cached data exists, even if isLoading is true
useBaseQuery.ts (line 378-390): Modified the Proxy handler to check isFetching state before accessing queryResource(). When isFetching is false and data exists in either state or observerResult, return it directly without triggering Suspense
suspense.test.tsx: Added test case to verify that Suspense is never triggered when using refetchOnMount: false with pre-cached data, including initial render and subsequent setQueryData calls
result
Jan-19-2026.00-07-02.1.mp4
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.