question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to configure useInfiniteQuery to concatenate pages in correct order when refetching stale query

See original GitHub issue

Describe the bug When using fetchMore(..., { previous: true }) to load a previous page and prepend it, if you then perform an action that causes ReactQuery to refetch, the requests are performed in the correct order but are appended instead of prepended. Currently there doesn’t seem to be a way to let ReactQuery know how it should reconstruct the refetched data.

To Reproduce Steps to reproduce the behavior:

  1. Go to this CodeSandbox which is a modified fork from the Infinite Loading example from the docs.
  2. Click on “Load more” a few times until no more messages can be loaded.
  3. Scroll down and click on “Go to another page”.
  4. Click on “Back” to return to messages.
  5. See that the query is refetched, but now the messages are displayed in an incorrect order.

Expected behavior If fetchMore(..., { previous: true }) is meant for infinite queries with a reversed direction, then useInfiniteQuery should accept some kind of option to indicate how background refetches should be handled.

Additional context I may be misunderstanding the purpose of the previous feature. If that’s the case then maybe additional details could be added to the docs to make it’s purpose clearer. Nonetheless, I would definitely recommend adding an appendMode option where the direction of the list can be configured. This will allow ReactQuery’s useInfiniteQuery to be used for reversed lists (such as chat messages, activity feeds, and the like).

PS: Issue #434 is related, and a possible solution seems to have been in development at some point, but I’m not sure if it ever got implemented or merged and the issue is now closed.

Thank you so much for the wonderful library! 🙂

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
tannerlinsleycommented, Sep 24, 2020

This is an interesting issue for sure. Totally makes sense. We’ll see what we can do about it!

1reaction
boschnicommented, Oct 6, 2020

Bi-directional navigation and reversed lists are now supported in v3! https://react-query-beta.tanstack.com/guides/infinite-queries

Read more comments on GitHub >

github_iconTop Results From Across the Web

No way to configure useInfiniteQuery to concatenate pages in ...
Click on "Back" to return to messages. See that the query is refetched, but now the messages are displayed in an incorrect order....
Read more >
Infinite Queries | TanStack Query Docs
When using useInfiniteQuery , you'll notice a few things are different: data is now an object containing infinite query data: data.pages array containing...
Read more >
ReactQuery - useInfiniteQuery refetching issue - Stack Overflow
If not, then setting a staleTime would be the best solution. If you do want a refetch, refetching all pages is the safest...
Read more >
react-query - npm
Hooks for managing, caching and syncing asynchronous and remote data in React. Latest version: 3.39.2, last published: 3 months ago.
Read more >
Async data made simple with React Query - Hey! I'm Tyler
A library of custom hooks that solves async data fetching and caching within React apps. We added react-query to a simple blog post...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found