fix(react-query): hydrate deferred queries before observers subscribe to avoid a redundant refetch #11137
Openostapondo(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/11137/headopened View on GitHubostapondo(GitHub profile, opens in a new tab) changed the title
ostapondo(GitHub profile, opens in a new tab) changed the title
- packages/react-query/src/__tests__/HydrationBoundary.test.tsx lines 152 to 160OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -149,11 +149,12 @@149149 </QueryClientProvider>,150150 )151151152- // Existing observer should not have updated at this point,153- // as that would indicate a side effect in the render phase154- expect(rendered.getByText('string')).toBeInTheDocument()152+ // The existing observer picks up the hydrated data once effects have153+ // flushed, but not during the render phase (the aborted transition154+ // test guards the render phase)155+ expect(rendered.getByText('should change')).toBeInTheDocument()155156 // New query data should be available immediately156157 expect(rendered.getByText('added')).toBeInTheDocument()157158158159 await vi.advanceTimersByTimeAsync(0)159- // After effects phase has had time to run, the observer should have updated160+ // Nothing changes after the effects phase has had time to run
ostapondo(GitHub profile, opens in a new tab) linked this to fix #9610
Sign in to join this conversation.
Note
Reviews paused#
It 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_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
a708d21a-baff-416f-8302-0783a50a5868📥 Commits
Reviewing files that changed from the base of the PR and between fca2f4cbad611e2fd48f6da18ba59d5121fd62a9 and ab12b643e5d64f39509c85929028788e51bd8d9a.
📒 Files selected for processing (1)
packages/react-query/src/__tests__/HydrationBoundary.test.tsx🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough#
HydrationBoundarynow hydrates deferred queries in an isomorphic layout effect. Tests verify immediate hydrated data and prevent redundant refetches when queries remount.Changes#
HydrationBoundary hydration timing
packages/react-query/src/HydrationBoundary.tsxHydrationBoundaryusesuseLayoutEffectin the browser anduseEffecton the server. Queued hydration runs after commit and before children’s passive subscriptions.packages/react-query/src/__tests__/HydrationBoundary.test.tsx,.changeset/hungry-planes-tease.mdEstimated code review effort: 3 (Moderate) | ~20 minutes
Possibly related issues
HydrationBoundary.Possibly related PRs
Sequence Diagram(s)#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#9610by hydrating before remounted observers can trigger a duplicate refetch.✨ 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.
❤️ Share