-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix/infinite query hydration 8825 #10074
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?
Conversation
🦋 Changeset detectedLatest commit: fe181a8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThe PR adds support for infinite queries during SSR hydration by introducing a queryType field to the DehydratedQuery interface, recording infinite query types during dehydration, applying infiniteQueryBehavior during hydration, and improving promise rejection handling to prevent unhandled errors. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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 |
Fixes #8825
Problem
When
prefetchInfiniteQueryfails on the server,useSuspenseInfiniteQueryon the client doesn't return the correct infinite query structure ({ pages: [], pageParams: [] }), causing a runtime error when accessingdata.pages:Root Cause
Infinite query behavior information gets lost during hydration:
infiniteQueryBehavioris attached whenprefetchInfiniteQueryruns on the serverInfiniteQueryObserverattaches the behaviorSolution
Set up infinite query behavior at hydration time to guarantee correct data structure for both success and failure cases.
Changes
1. Added
queryTypefield toDehydratedQuery'query' | 'infiniteQuery'value2. Auto-detect query type during dehydration
initialPageParampresence to identify infinite queriesqueryTypefield3. Auto-configure behavior during hydration
infiniteQueryBehaviorwhenqueryTypeis'infiniteQuery'4. Handle failed promises
initialPromiseModified Files
packages/query-core/src/hydration.tspackages/query-core/src/__tests__/hydration.test.tsxTests
All 35 tests passing (including 2 new tests)
New tests added:
should preserve queryType for infinite queries during hydrationshould attach infiniteQueryBehavior during hydrationChecklist
queryType: 'query' | 'infiniteQuery'field toDehydratedQueryinitialPageParaminfiniteQueryBehaviorfor infinite queries during hydrationSummary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.