-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite query page param resets back to the first page during refetch if a page request is retried #8046
Comments
incepter
added a commit
to incepter/query
that referenced
this issue
Sep 12, 2024
TkDodo
added a commit
that referenced
this issue
Sep 12, 2024
* Add reproduction test for infinite loop retries (issue #8046) * ci: apply automated fixes * fix: retry for infinite queries The retryer lives above the fetchFn, and it re-runs the fetchFn whenever a retry happens. Usually, the fetchFn is a thin wrapper around the actual queryFn passed by the user. However, for infinite queries, it fetches all pages in a loop. The retryer breaks out of this loop if an error occurs on e.g. the second page, and then retries by running the fetchFn - which will re-set the loop This fix hoists the currentPage counter out of the fetchFn - into the closure created by onFetch. The outer closure is created from running `query.fetch` once, so it won't be re-set between retries. The fix also re-writes the fetch loop to always take the `currentPage` into account, where it was previously treating the first page differently --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Dominik Dorfmeister <[email protected]>
This was referenced Oct 3, 2024
Closed
Merged
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I am using
useInfiniteQuery
to additively load more data into a table from anextToken
based list API (e.g. example AWS SDK list API). Requesting next pages and refetching works great for the most part, but I'm having some trouble figuring out a way to preserve the next page param for a retried request triggered by a manual or automatedrefetch
.When fetching next pages with
fetchNextPage
and thequeryFn
rejects with an error response, the request is retried as expected using the same page params. However, I noticed retried requests from a manual or automatedrefetch
will start over back to the first page after the first error response is encountered. I understand the need to fetch sequentially from the first page for the refetch, however, I would expect the failed request to retry using the same page params and continue onto the next page request once a retry succeeds.The backend service I'm working with has a reasonable rate limit set (50 TPM in a 1 minute sliding window), but I'm trying to ensure a manual or automatic
refetch
will be able to recover from worst-case rate limiting scenarios where the user can continuously rate-limit themselves by refetching a table view loaded with 50+ pages.Original discussion: #8044
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/mqvdz4
Steps to reproduce
refetch
.0
during the refetch when the rate limiting error is encountered with page2
. This will continue to loop until the number of retry attempts are exhausted.Example console logs:
Expected behavior
During a manual and automated infinite query refetch, I expect a failed page request to retry using the same page params and continue onto the next page request once the retry succeeds. Currently, infinite query refetch will start over back to the first page for retry attempts after the first error response is encountered.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
v5.51.23
TypeScript version
v5.2.2
Additional context
No response
The text was updated successfully, but these errors were encountered: