Skip to content
Source
Sign inSign up
TanStack/query

`failureCount` in the retry callback starts at zero #10017

Closedblowery(GitHub profile, opens in a new tab) opened this issue 6 comments

Describe the bug

The docs on the retry query option for the callback variant do not spell out that failureCount starts at zero. It was a bit surprising and it would nice to call that out, assuming it's intentional. The first retry check will have failureCount === 0.

Your minimal, reproducible example

https://tanstack.com/query/latest/docs/framework/react/reference/useQuery

Steps to reproduce

none

Expected behavior

I expected the docs to document that failureCount is 0 on the first callback and not 1.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

all

Tanstack Query adapter

None

TanStack Query version

v5

TypeScript version

No response

Additional context

No response

  1. I actually think this might be a bug. It should be 1 on the first callback. We already have an error, so the failureCount shouldn’t be zero 😅

  2. TkDodo added labelspackage: query-core

  3. TkDodo changed the title

  4. @TkDodo Since the retry callback is invoked after a failure has already occurred, passing failureCount + 1 to the callback could resolve the semantic mismatch without touching the core retry behavior. Would that be okay?

    If this approach looks good to you, I’d like to take this on and work on the fix.

  5. I thought about this a bit and I don’t think we should introduce this change in behavior in a minor. An argument can be made for both ways and changing it just because might break existing usages.

    I think it’s best if we just document the current behavior and maybe re-think if a change is worth it in the next major.

  6. Hi @TkDodo I can work on documenting the current behavior of failureCount starting at 0 in the retry callback, as discussed here. Please let me know if that’s okay

  7. Go for it

  8. Hi maintainers 👋 I’d like to work on this issue. Please let me know if it’s already assigned to someone. Thanks!

  9. TkDodo closed this

Sign in to join this conversation.