Skip to content

useInfiniteQuery: fetchNextPage cancels all refetches, including those triggered by cache invalidation #5972

@LeshaTat

Description

@LeshaTat

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

  1. Hide the list by clicking on "Toggle".
  2. Click "Invalidate".
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions