Skip to content

Commit 6020706

Browse files
fix:(prefetchQuery): override default retry behaviour to false (TanStack#760)
1 parent ef9d47b commit 6020706

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/core/queryCache.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ export function makeQueryCache({ frozen = isServer, defaultConfig } = {}) {
208208

209209
let [queryKey, config, { force, throwOnError } = {}] = getQueryArgs(args)
210210

211+
// https://github.com/tannerlinsley/react-query/issues/652
212+
config = { retry: false, ...config }
213+
211214
try {
212215
const query = queryCache.buildQuery(queryKey, config)
213216
if (force || query.state.isStale) {

src/core/tests/queryCache.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ describe('queryCache', () => {
2323
).not.toThrow()
2424
})
2525

26+
// https://github.com/tannerlinsley/react-query/issues/652
27+
test('prefetchQuery should not retry by default', async () => {
28+
await expect(
29+
queryCache.prefetchQuery(
30+
'key',
31+
async () => {
32+
throw new Error('error')
33+
},
34+
{},
35+
{ throwOnError: true }
36+
)
37+
).rejects.toEqual(new Error('error'))
38+
})
39+
2640
test('prefetchQuery returns the cached data on cache hits', async () => {
2741
const fetchFn = () => Promise.resolve('data')
2842
const first = await queryCache.prefetchQuery('key', fetchFn)

0 commit comments

Comments
 (0)