Skip to content

useInfiniteQuery does not keep previous data on new fetching #1945

@gritaliana

Description

@gritaliana

Describe the bug
I have been using version 3.8.2 of react-query and after updating to version 3.12.0 this bug appears. I am using useInfiniteQuery with param keepPreviousData: true, which in 3.8.2 was working fine and while updating the query by filter changing (new fetching) it was keeping previous data till new data has come.
But in 3.12.0 while query has isFetching: true and isFetched: true it returns data.pages: [] as an empty array, and isPreviousData: false and this is not what expected by using param keepPreviousData: true. Because there was data before this fetch.

To Reproduce
For the page with some filter and a list of items create useInfiniteQuery with param keepPreviousData: true.
It looks like: useInfiniteQuery({
queryKey: ['module', query],
queryFn: async () {},
keepPreviousData: true,
})

Then while changing query from the filters it starts fetching the list with new query params. And while it is isFetching: true and isFetched: false it still has isPreviousData: true and returns data.pages with old items, but as long as infiniteQuery has updated to isFetching: true and isFetched: true it clears the data.pages and returns isPreviousData: false. Then, when isFetching: false I finally have data, which is new. But where is the old data in the middle of fetching?

Expected behavior
While using param keepPreviousData: true in useInfiniteQuery it is expected that in the middle of fetching data.pages would not return an empty array if there was data previously. As it works in version 3.8.2.

Screenshots
Still have old data
image

Here it clears old data
image

Fetched new data:
image

Desktop:

  • OS: iOS
  • Browser: chrome
  • Version: 88.0.4324.192

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