-
-
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: 161c143 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 |
📝 WalkthroughWalkthroughAdds explicit support for infinite queries during de/rehydration: dehydration records Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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 |
|
View your CI Pipeline Execution ↗ for commit 161c143
☁️ Nx Cloud last updated this comment at |
| const queryOptions: any = { | ||
| ...client.getDefaultOptions().hydrate?.queries, | ||
| ...options?.defaultOptions?.queries, | ||
| queryKey, | ||
| queryHash, | ||
| meta, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep this inlined please and just conditionally assign behavior:
behavior: queryType === 'infiniteQuery'
? (infiniteQueryBehavior() as QueryBehavior<unknown, unknown, unknown>)
: undefined,
| const isRejectedThenable = | ||
| promise && | ||
| typeof promise === 'object' && | ||
| 'status' in promise && | ||
| (promise as any).status === 'rejected' | ||
|
|
||
| if (!isRejectedThenable) { | ||
| query | ||
| .fetch(undefined, { | ||
| // RSC transformed promises are not thenable | ||
| initialPromise: Promise.resolve(promise).then((resolvedData) => { | ||
| return deserializeData(resolvedData) | ||
| }), | ||
| }) | ||
| // Avoid unhandled promise rejections | ||
| .catch(noop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t understand what this change has to do with infinite queries ?
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
Bug Fixes
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.