Skip to content

Commit 7f9a52a

Browse files
committed
Retry now checks whether potential retry counts are undefined, rather than boolean, in order to avoid filtering out 0's
1 parent 026221a commit 7f9a52a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/toolkit/src/query/retry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const retryWithBackoff: BaseQueryEnhancer<
8383
5,
8484
((defaultOptions as any) || EMPTY_OPTIONS).maxRetries,
8585
((extraOptions as any) || EMPTY_OPTIONS).maxRetries,
86-
].filter(Boolean)
86+
].filter(x => x !== undefined)
8787
const [maxRetries] = possibleMaxRetries.slice(-1)
8888

8989
const defaultRetryCondition: RetryConditionFunction = (_, __, { attempt }) =>

packages/toolkit/src/query/tests/retry.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,33 @@ describe('configuration', () => {
439439
expect(baseBaseQuery).toHaveBeenCalledTimes(4)
440440
})
441441

442+
test('Specifying maxRetries as 0 in RetryOptions prevents retries', async () => {
443+
const baseBaseQuery = jest.fn<
444+
ReturnType<BaseQueryFn>,
445+
Parameters<BaseQueryFn>
446+
>()
447+
baseBaseQuery.mockResolvedValue({ error: 'rejected' })
448+
449+
const baseQuery = retry(baseBaseQuery, { maxRetries: 0 })
450+
const api = createApi({
451+
baseQuery,
452+
endpoints: (build) => ({
453+
q1: build.query({
454+
query: () => {},
455+
}),
456+
}),
457+
})
458+
459+
const storeRef = setupApiStore(api, undefined, {
460+
withoutTestLifecycles: true,
461+
})
462+
463+
storeRef.store.dispatch(api.endpoints.q1.initiate({}))
464+
await loopTimers(2)
465+
466+
expect(baseBaseQuery).toHaveBeenCalledTimes(1)
467+
});
468+
442469
test.skip('RetryOptions only accepts one of maxRetries or retryCondition', () => {
443470
// @ts-expect-error Should complain if both exist at once
444471
const ro: RetryOptions = {

0 commit comments

Comments
 (0)