-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Describe the bug
Using useInfiniteQuery
, I would like to manually handle errors that occur during fetchNextPage
or fetchPreviousPage
, while displaying a generic message for errors that occur during initial load isLoadingError
or refetch isRefetchError
.
The fetchNextPage
and fetchPreviousPage
methods returns an isError
property that can be used to show a message when a next/previous page fetch fails, however, there's no query-level property that allows you to differentiate between an initial load error, refetch error, and next/previous page fetch error.
Property | Initial Load | Refetch Page | Next Page | Previous Page |
---|---|---|---|---|
status |
✅ | ✅ | ✅ | ✅ |
isError |
✅ | ✅ | ✅ | ✅ |
isLoadingError |
✅ | ❌ | ❌ | ❌ |
isRefetchError |
❌ | ✅ | ✅ | ✅ |
Your minimal, reproducible example
https://codesandbox.io/p/devbox/dank-tdd-plsmw6
Steps to reproduce
- Create a paginated query using
useInfiniteQuery
. - Call
fetchNextPage
while simulating an API error.
Note: query.isRefetchError
now equals true
, making it impossible to differentiate refetch errors from next/previous page fetch errors.
Expected behavior
I would expect isRefetchError
to only be true
when a refetch error occurs (i.e. while reloading a previously loaded page).
Notably, while fetchNextPage
is loading:
isRefetching
:false
isFetchingNextPage
:true
.
This suggests that perhaps there should be more granular isFetchingNextPageError
and isFetchingPreviousPageError
properties to handle these specific scenarios.
Property | Initial Load | Refetch Page | Next Page | Previous Page |
---|---|---|---|---|
status |
✅ | ✅ | ✅ | ✅ |
isError |
✅ | ✅ | ✅ | ✅ |
isLoadingError |
✅ | ❌ | ❌ | ❌ |
isRefetchError |
❌ | ✅ | ❌ | ❌ |
isFetchNextPageError |
❌ | ❌ | ✅ | ❌ |
isFetchPreviousPageError |
❌ | ❌ | ❌ | ✅ |
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Safari
- Version: 17.4.1
Tanstack Query adapter
react-query
TanStack Query version
5.35.5
TypeScript version
No response
Additional context
No response