| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting. Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR prevents unnecessary Solid Suspense activation when query data is already cached (including ensureQueryData preloads) by changing the data getter to return cached state.data only when no fetch is in-flight, adding a regression test, and adding a changeset note. ChangesSolid Query Suspense Fix
Sequence Diagram(s)sequenceDiagram
participant Component
participant useBaseQuery
participant QueryResource
participant QueryClient
Component->>useBaseQuery: read data
useBaseQuery->>useBaseQuery: check state.data
useBaseQuery->>useBaseQuery: untrack(state.isFetching)
alt not fetching and state.data present
useBaseQuery-->>Component: return cached state.data
else fetching or no cached data
useBaseQuery->>QueryResource: read resource (may suspend)
QueryResource-->>useBaseQuery: resource.data
useBaseQuery-->>Component: return resource.data (or suspend)
end
Note right of QueryClient: ensureQueryData preloads cache used above
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem🚥 Pre-merge checks | ✅ 4 | ❌ 1 ❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches 🧪 Generate unit tests (beta)
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
|
View your CI Pipeline Execution ↗ for commit 654c8e7
☁️ Nx Cloud last updated this comment at 2026-05-11 08:26:23 UTC |
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
packages/solid-query/src/__tests__/suspense.test.tsx (1)🤖 Prompt for all review comments with AI agents911-950: ⚡ Quick win
Consider spying on the Page query function to assert it was never invoked.
The test correctly guards against the fallback mounting, but it does not verify that the background queryFn (returning 'fresh') is never called. A vi.fn() spy would make the test more explicit about the "no refetch" contract implied by staleTime: Infinity, and would catch regressions where the fix avoids Suspense but still triggers an unintended network call.
✅ Suggested improvement+ const freshFn = vi.fn(() => sleep(10).then(() => 'fresh')) + function Page() { const state = useQuery(() => ({ queryKey: key, - queryFn: () => sleep(10).then(() => 'fresh'), + queryFn: freshFn, staleTime: Infinity, })) return <div>data: {state.data}</div> }Then add at the end:
🤖 Prompt for AI Agentsexpect(rendered.getByText('data: preloaded')).toBeInTheDocument() expect(fallbackMounted).toBe(false) + expect(freshFn).not.toHaveBeenCalled() })Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/solid-query/src/__tests__/suspense.test.tsx` around lines 911 - 950, Add a vi.fn() spy for the queryFn used inside the Page component and assert it was never called after render: replace the inline queryFn in Page's useQuery with a spied function (e.g., const pageQueryFn = vi.fn(() => sleep(10).then(() => 'fresh')) and pass that to useQuery), then after rendering assert pageQueryFn was not called (expect(pageQueryFn).not.toHaveBeenCalled()) to ensure the background refetch never ran; keep the ensureQueryData preload untouched.
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Nitpick comments: In `@packages/solid-query/src/__tests__/suspense.test.tsx`: - Around line 911-950: Add a vi.fn() spy for the queryFn used inside the Page component and assert it was never called after render: replace the inline queryFn in Page's useQuery with a spied function (e.g., const pageQueryFn = vi.fn(() => sleep(10).then(() => 'fresh')) and pass that to useQuery), then after rendering assert pageQueryFn was not called (expect(pageQueryFn).not.toHaveBeenCalled()) to ensure the background refetch never ran; keep the ensureQueryData preload untouched.
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 39a9d48e-01a7-4062-9fd2-663ae1782d1f
📥 CommitsReviewing files that changed from the base of the PR and between c947290 and 7a99cf8.
📒 Files selected for processing (3)
Sorry, something went wrong.
Address CodeRabbit nitpick on PR TanStack#10592: spy on Page's queryFn and assert it was never called, strengthening the guarantee that the background refetch did not run when data was preloaded via ensureQueryData. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Addressed CodeRabbit nitpick in e815276: spied on Page's queryFn with vi.fn() and added expect(pageQueryFn).not.toHaveBeenCalled() to assert the background refetch never ran. |
Sorry, something went wrong.
Address CodeRabbit nitpick on PR TanStack#10592: spy on Page's queryFn and assert it was never called, strengthening the guarantee that the background refetch did not run when data was preloaded via ensureQueryData. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address CodeRabbit nitpick on PR TanStack#10592: spy on Page's queryFn and assert it was never called, strengthening the guarantee that the background refetch did not run when data was preloaded via ensureQueryData. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address CodeRabbit nitpick on PR TanStack#10592: spy on Page's queryFn and assert it was never called, strengthening the guarantee that the background refetch did not run when data was preloaded via ensureQueryData. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When data was preloaded via `ensureQueryData` (e.g. from a router loader), the proxy `data` getter read `queryResource.latest`, which falls back to a suspending read while the resource is in its initial pending state, even though the fetcher had already synchronously resolved with cached data. If the store already has data and no fetch is in-flight, return `state.data` directly. `state.isFetching` is read via `untrack` so it doesn't widen the data subscriber's reactive deps. Fixes TanStack#9955
Address CodeRabbit nitpick on PR TanStack#10592: spy on Page's queryFn and assert it was never called, strengthening the guarantee that the background refetch did not run when data was preloaded via ensureQueryData. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #9955.
When data was preloaded via ensureQueryData (e.g. from a TanStack Router loader), accessing state.data in a Suspense boundary would re-trigger the Suspense fallback even though the data was already in cache and isSuccess was true.
Root cause
In useBaseQuery.ts, the proxy data getter reads queryResource.latest?.data whenever state.data !== undefined. Per Solid's docs, .latest falls back to a read()-equivalent (and therefore triggers Suspense) when the resource has no prior resolved value.
In the preloaded-cache case, the resource's fetcher synchronously calls resolve(...) because !observerResult.isLoading, but the resource doesn't transition out of the initial pending state until the next microtask. Reading .latest inside that microtask gap suspends the component even though state.data already holds the cached value.
Fix
If the store already has data and no fetch is in-flight (!state.isFetching), return state.data directly without going through queryResource. state.isFetching is read via untrack so it doesn't widen the data subscriber's reactive deps (preserves existing reconcile / memo-churn tests).
When a fetch is in-flight, the existing queryResource.latest?.data path is preserved so background-refresh and re-mount semantics are unchanged.
Verification
Test plan
🤖 Generated with Claude Code
Generated by Ora Studio
Vibe coded by ousamabenyounes
Summary by CodeRabbit
Bug Fixes
Tests
Chores
Generated by Ora Studio (with Claude Code)
Vibe coded by Ben Younes Ousama