fix(react-query): hydrate disabled query shells in HydrationBoundary#10535
fix(react-query): hydrate disabled query shells in HydrationBoundary#10535byungsker wants to merge 1 commit intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/HydrationBoundary.test.tsx (1)
516-567: Good regression test; theclientQueryFnassertion is what actually proves render-phase hydration.The key signal here is
expect(clientQueryFn).toHaveBeenCalledTimes(0)— under the old behavior,Child'suseSuspenseQuerywould suspend beforeHydrationBoundary's effect ran, triggering a fetch. The cache-statetoMatchObjectassertion on its own doesn't distinguish render-phase vs effect-phase hydration (effects have already flushed by then), so it's good that the test pairs both.One optional tweak: consider also asserting that
Childdid not throw/suspend beyond the synchronous render (e.g.queryByText('loading')is null) to make the render-phase guarantee more explicit in the test output.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/HydrationBoundary.test.tsx` around lines 516 - 567, Add an assertion that the Suspense fallback did not render synchronously to make the render-phase hydration guarantee explicit: after renderWithClient(...) and before clearing the client, query the rendered output for the Suspense fallback text (e.g. "loading") and assert it is not present; this should reference the existing Child component / useSuspenseQuery and the clientQueryFn assertion so the test proves Child did not suspend during render while HydrationBoundary applied the dehydrated state.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/react-query/src/__tests__/HydrationBoundary.test.tsx`:
- Around line 516-567: Add an assertion that the Suspense fallback did not
render synchronously to make the render-phase hydration guarantee explicit:
after renderWithClient(...) and before clearing the client, query the rendered
output for the Suspense fallback text (e.g. "loading") and assert it is not
present; this should reference the existing Child component / useSuspenseQuery
and the clientQueryFn assertion so the test proves Child did not suspend during
render while HydrationBoundary applied the dehydrated state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 64a5774f-c3ca-4e98-8ed1-31e8a671d310
📒 Files selected for processing (4)
.changeset/fix-hydration-boundary-disabled-shell.mdpackages/query-core/src/__tests__/hydration.test.tsxpackages/react-query/src/HydrationBoundary.tsxpackages/react-query/src/__tests__/HydrationBoundary.test.tsx
|
Closing this as a duplicate of #10159, which was already opened by the issue author. Apologies for the noise! |
🎯 Changes
Fixes #10145
When a query with the same key already exists in the cache,
HydrationBoundarycurrently defers hydration until the effect phase — which is correct for active queries during transitions.However, this also applies to queries that are only a disabled idle shell with no data yet. In that case, a nested
useSuspenseQuerycan mount before the prefetched data is applied and unnecessarily suspend or refetch.This PR makes
HydrationBoundaryhydrate existing queries immediately during render when they areidle, disabled, and have no data — treating them as effectively empty shells rather than active queries worth preserving.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
HydrationBoundaryto correctly handle hydration of disabled query shells, ensuring they are properly hydrated during the render phase instead of being deferred to after rendering.