-
-
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: 7c41b00 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 handling for infinite queries in de/rehydration: dehydrated queries now include a Changes
Sequence Diagram(s)sequenceDiagram
participant Server as Server (prefetch)
participant Dehydrator as Dehydrator
participant Serialized as Dehydrated State
participant Client as Client (hydrate)
participant QueryClient as QueryClient
Server->>Dehydrator: prefetchInfiniteQuery (pages, pageParams)
Dehydrator->>Serialized: dehydrate(query + queryType:'infiniteQuery')
Serialized-->>Client: send dehydrated state
Client->>QueryClient: hydrate(state)
QueryClient->>QueryClient: restore query (read queryType)
alt queryType == 'infiniteQuery'
QueryClient->>QueryClient: apply infiniteQueryBehavior to restored options
end
Client->>QueryClient: fetchInfiniteQuery() -> uses restored behavior and pages/pageParams
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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
🧪 Generate unit tests (beta)
Tip 🧪 Unit Test Generation v2 is now available!We have significantly improved our unit test generation capabilities. To enable: Add this to your reviews:
finishing_touches:
unit_tests:
enabled: trueTry it out by using the Have feedback? Share your thoughts on our Discord thread! 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 |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:sherif,test:knip,tes... |
❌ Failed | 4m 20s | View ↗ |
nx run-many --target=build --exclude=examples/*... |
✅ Succeeded | 2s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-30 09:25:05 UTC
| 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,
packages/query-core/src/hydration.ts
Outdated
| 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 ?
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.
- Remove isRejectedThenable check - Inline behavior assignment
161c143 to
7c41b00
Compare

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.