-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Describe the bug
When using fetchNextPage with the cancelRefetch: true option (which is the default), all refetching, including refetching after cache invalidation, is canceled. The documentation explicitly states that with this option enabled, fetchNextPage will cancel the previous invocations, not every refetch attempt. This leads to hard-to-debug errors where server requests are correctly executed, but the cache doesn't update.
Real-life Example
In React Native, you put lists into FlatList that has an onEndReached property. When you specify onEndReached={()=>fetchNextPage}, and if the list is short, this request starts immediately after mounting the list and prevents refetching if the data was loaded before.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/modern-lake-yslmds?file=%2Fsrc%2FApp.js%3A1%2C24
Steps to reproduce
- Hide the list by clicking on "Toggle".
- Click "Invalidate".
- Untoggle the list back.
Expected behavior
The list should update.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
React Native
Tanstack Query adapter
react-query
TanStack Query version
v5.0.0-beta.20
TypeScript version
No response
Additional context
The issue also appears in previous versions of React Query.