Skip to content

Commit

Permalink
fix:(prefetchQuery): override default retry behaviour to false (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
otaciliolacerda authored Jul 16, 2020
1 parent ef9d47b commit 6020706
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/queryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ export function makeQueryCache({ frozen = isServer, defaultConfig } = {}) {

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

// https://github.com/tannerlinsley/react-query/issues/652
config = { retry: false, ...config }

try {
const query = queryCache.buildQuery(queryKey, config)
if (force || query.state.isStale) {
Expand Down
14 changes: 14 additions & 0 deletions src/core/tests/queryCache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ describe('queryCache', () => {
).not.toThrow()
})

// https://github.com/tannerlinsley/react-query/issues/652
test('prefetchQuery should not retry by default', async () => {
await expect(
queryCache.prefetchQuery(
'key',
async () => {
throw new Error('error')
},
{},
{ throwOnError: true }
)
).rejects.toEqual(new Error('error'))
})

test('prefetchQuery returns the cached data on cache hits', async () => {
const fetchFn = () => Promise.resolve('data')
const first = await queryCache.prefetchQuery('key', fetchFn)
Expand Down

1 comment on commit 6020706

@vercel
Copy link

@vercel vercel bot commented on 6020706 Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.