-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(react-query): support server snapshots during hydration #11500
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
Open
DogPawHat
wants to merge
4
commits into
TanStack:main
Choose a base branch
from
DogPawHat:query-ssr-snapshot-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+479
−14
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2a83ad6
feat(react-query): support server snapshots during hydration
DogPawHat 5fc2c17
feat(react-query): support server snapshot hydration options
DogPawHat 956d7b8
fix(react-query): scope server snapshots to hydration boundaries
DogPawHat e87d985
Merge branch 'main' into query-ssr-snapshot-transport
DogPawHat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/react-query': patch | ||
| --- | ||
|
|
||
| Make queries inside a `HydrationBoundary` replay the boundary's server-rendered state during hydration before switching to the live cache. This prevents hydration mismatches when the cache changes before browser hydration, including when a query above the boundary creates an empty cache entry or a streamed promise resolves early. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: TanStack/query
Length of output: 34804
🤖 get_repo_knowledge executed:
get_repo_knowledge TanStack/query /tmp/coderabbit-repo-knowledge/tanstack-query-2191d1d3/learningsLength of output: 1671
🏁 Script executed:
Repository: TanStack/query
Length of output: 50372
Preserve snapshots from outer hydration boundaries.
HydrationBoundaryreplaces the nearestQueryServerSnapshotContextwith its ownsnapshotClient. If an inner boundary has no state or lacks the currentqueryHash,useBaseQuerycannot find an ancestor snapshot and falls back to the live observer result.The live result can differ from the outer server snapshot during the first hydration render. Preserve a chain of snapshot clients and use the live cache only after all ancestor snapshots miss. Add a nested-boundary regression test with an outer pending query and an empty or unrelated inner state.
🤖 Prompt for AI Agents
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.
Are you concerned about nested hydration boundaries?
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 9474
@DogPawHat, yes. I verified the nested-boundary case.useBaseQueryreads only the nearestQueryServerSnapshotContext. An innerHydrationBoundaryalways provides its ownsnapshotClient. If that client isundefined, empty, or does not containdefaultedOptions.queryHash, Lines 108-117 return no server snapshot. Line 129 then falls back to the live observer result.Therefore, an outer boundary’s matching snapshot is not available to queries inside an inner boundary. The concern applies only to nested boundaries where the inner snapshot misses and the live cache has advanced before client hydration.
You are interacting with an AI system.