fix(query-core): fix hydration bugs for already resolved promises #10444
main fromrefs/pull/10444/headmerged by Ephem(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-core
- packages/query-core/src/hydration.ts lines 239 to 247OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -236,3 +236,12 @@236236 query.setState({237237 ...serializedState,238238 data,239+ // if data was resolved synchronously, transition to success240+ // (mirrors the new-query branch below), but preserve fetchStatus241+ // if the query is already actively fetching242+ ...(data !== undefined && {243+ status: 'success' as const,244+ ...(!existingQueryIsFetching && {245+ fetchStatus: 'idle' as const,246+ }),247+ }),
TkDodo approved these changes
github-actions[bot](GitHub profile, opens in a new tab) added labelsdocumentation
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-query-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-query-persist-client
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-persist-client-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: eslint-plugin-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: svelte-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: svelte-query-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: angular-query-experimental
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-async-storage-persister
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-sync-storage-persister
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-query-persist-client
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: svelte-query-persist-client
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-query-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-query-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-broadcast-client-experimental
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-query-next-experimental
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: angular-query-persist-client
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: preact-query
Ephem(GitHub profile, opens in a new tab) removed labelsdocumentation
Ephem(GitHub profile, opens in a new tab) removed labelspackage: react-query-devtools
Ephem(GitHub profile, opens in a new tab) removed labelspackage: react-query-persist-client
Ephem(GitHub profile, opens in a new tab) removed labelspackage: vue-query
Ephem(GitHub profile, opens in a new tab) removed labelspackage: solid-query
Ephem(GitHub profile, opens in a new tab) removed labelspackage: query-persist-client-core
Ephem(GitHub profile, opens in a new tab) removed labelspackage: eslint-plugin-query
Ephem(GitHub profile, opens in a new tab) removed labelspackage: svelte-query
Ephem(GitHub profile, opens in a new tab) removed labelspackage: svelte-query-devtools
Ephem(GitHub profile, opens in a new tab) removed labelspackage: query-devtools
Ephem(GitHub profile, opens in a new tab) removed labelspackage: angular-query-experimental
Ephem(GitHub profile, opens in a new tab) removed labelspackage: query-async-storage-persister
Ephem(GitHub profile, opens in a new tab) removed labelspackage: query-sync-storage-persister
Ephem(GitHub profile, opens in a new tab) removed labelspackage: solid-query-persist-client
Ephem(GitHub profile, opens in a new tab) removed labelspackage: svelte-query-persist-client
Ephem(GitHub profile, opens in a new tab) removed labelspackage: vue-query-devtools
Ephem(GitHub profile, opens in a new tab) removed labelspackage: solid-query-devtools
Ephem(GitHub profile, opens in a new tab) removed labelspackage: query-broadcast-client-experimental
Ephem(GitHub profile, opens in a new tab) removed labelspackage: react-query-next-experimental
Ephem(GitHub profile, opens in a new tab) removed labelspackage: angular-query-persist-client
Ephem(GitHub profile, opens in a new tab) removed labelspackage: preact-query
Ephem(GitHub profile, opens in a new tab) removed labelspackage: react-query
- packages/query-core/src/__tests__/hydration.test.tsx lines 1394 to 1505OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1387,0 +1485,21 @@1485+ const { status, fetchStatus } = event.query.state1486+ states.push({ status, fetchStatus })1487+ }1488+ })1489+1490+ hydrate(clientQueryClient, dehydrated)1491+ await vi.advanceTimersByTimeAsync(0)1492+ unsubscribe()1493+1494+ expect(states).not.toContainEqual(1495+ expect.objectContaining({ fetchStatus: 'fetching' }),1496+ )1497+ expect(states).not.toContainEqual(1498+ expect.objectContaining({ status: 'pending' }),1499+ )1500+1501+ clientQueryClient.clear()1502+ serverQueryClient.clear()1503+ })1504+1505+ test('should not transition to a fetching/pending state when hydrating an already resolved promise into an existing query', async () => {
Ephem(GitHub profile, opens in a new tab) merged this1bb0d23
Ephem(GitHub profile, opens in a new tab) closed this
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
Run ID:
2465a54d-763d-4451-9972-0212c446e5c0📥 Commits
Reviewing files that changed from the base of the PR and between 27e3412dc3640c3d2c3ca30dbe0065722decadda and 652375e4037c2404ebab53ee3b13a47944294321.
📒 Files selected for processing (1)
packages/query-core/src/__tests__/hydration.test.tsx📝 Walkthrough
Walkthrough#
Hydration behavior was changed so dehydrated queries whose promises already resolved are treated as successful; retryer creation and query.fetch calls are skipped for synchronously-resolved thenables. Tests and a changeset were added to cover streaming/hydration synchronous-thenable scenarios.
Changes#
.changeset/shy-wings-buy.md@tanstack/query-coredocumenting the hydration fix for synchronously-resolved promises.packages/query-core/src/__tests__/hydration.test.tsxpending/fetchingstates or intermediate fetching updates are emitted.packages/query-core/src/hydration.tspendingstates with defineddatatosuccess(without overriding an actively fetchingfetchStatus), and avoid creating a retryer or callingquery.fetchwhen the dehydrated promise resolved synchronously.Sequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~45 minutes
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#9642by fixing both hydration bugs: handling existing queries in cache [hydration.ts] and preventing incorrect fetch calls for resolved promises [hydration.ts, tests].✨ 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