Skip to content
Source
Sign inSign up
TanStack/query

Prevent useQuery from skipping hydration #10159

ClosedColemanDunn(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/10159/headopened View on GitHub

Showing 5 changed files with 100 additions and 13 deletions (loading 2).

x
0 of 5 viewed, 5 left
6 additions and 0 deletions.changeset/moody-cities-stand.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/react-query': patch
+'@tanstack/query-core': patch
+---
+​
+prevent registered useQueries from skipping hydration
73 additions and 0 deletionspackages/query-core/src/__tests__/hydration.test.tsxModified
View file
@@ -2,6 +2,7 @@
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { QueryClient } from '../queryClient'
import { QueryCache } from '../queryCache'
+import { QueryObserver } from '../queryObserver'
import { dehydrate, hydrate } from '../hydration'
import { MutationCache } from '../mutationCache'
import { executeMutation, mockOnlineManagerIsOnline } from './utils'
@@ -1804,4 +1805,76 @@
clientQueryClient.clear()
serverQueryClient.clear()
+​
+ it('should not transition to a fetching/pending state when hydrating an already resolved promise into an idle pending query', async () => {
+ const key = queryKey()
+ // --- server ---
+ const serverQueryClient = new QueryClient({
+ defaultOptions: {
+ dehydrate: { shouldDehydrateQuery: () => true },
+ },