Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): use a hydrated query's current 'retry' options when it rejects #12511

OpenKATT(GitHub profile, opens in a new tab)wants to merge 14 commits intomain fromrefs/pull/12511/headopened View on GitHub

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

x
0 of 5 viewed, 5 left
5 additions and 0 deletions.changeset/hydrated-rejection-retry.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-core': patch
+---
+​
+When a query hydrated while pending rejects, its retries now take `retry` and `retryDelay` from the options an observer set itself, if one mounted before the promise settled. Otherwise they use the hydration options, and then the client's defaults, as before.
134 additions and 0 deletionspackages/query-core/src/__tests__/hydration.test.tsxModified
View file
@@ -5,6 +5,7 @@
import { dehydrate, hydrate } from '../hydration'
import { dehydrateQuery } from '../index'
import { MutationCache } from '../mutationCache'
+import { QueryObserver } from '../queryObserver'
import { noop } from '../utils'
import { executeMutation, mockOnlineManagerIsOnline } from './utils'
import type { MutationFunction, MutationFunctionContext } from '../index'
@@ -1096,6 +1097,139 @@
+ it("should retry a hydrated query that rejects with the observer's retry and retryDelay", async () => {
+ const key = createKey()
+ // 🖥️ Server: still pending at dehydrate, rejects later
+ const serverClient = new QueryClient()
+ void serverClient
+ .query({
+ queryKey: key,
+ queryFn: () => sleep(10).then(() => Promise.reject(new Error('error'))),
+ retry: false,