scroll restoration doesn't work when using IsFetching #3180
-
When I use isLoading like pseudo code below, scroll restoration works well when I go to the detail page and return. (using the brower back button)
But, When I use isFetching instead, scroll restoration doesn't work at all.
I already read some answers like #2493 (comment), and #1977 (comment), so I understand that react-query doesn't do anything specific for scroll restoration. But, I want to show "loading component" instead of cached data When the query is fetching in the background, becuase I guess it confuses the user if the data is updated on the screen while user is watching. Thank you for your time. :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't think there is. if you unmount your component during every background refetch, the scroll position is gone. it also means that every time you focus the window (unless you turn that feature off or customize staleTime), your component would unmount and a loading spinner is shown. a better ux would likely be to show a background loading spinner in addition to the stale data, and maybe a success toast after the data has been fetched to show the users that they are now seeing new data. but the stale-while-revalidate principle react-query is built upon usually leads to a better ux if you keep showing stale data instead of a loading spinner while background updates are happening. otherwise, you're not really taking advantage of the cache. |
Beta Was this translation helpful? Give feedback.
I don't think there is. if you unmount your component during every background refetch, the scroll position is gone. it also means that every time you focus the window (unless you turn that feature off or customize staleTime), your component would unmount and a loading spinner is shown.
a better ux would likely be to show a background loading spinner in addition to the stale data, and maybe a success toast after the data has been fetched to show the users that they are now seeing new data. but the stale-while-revalidate principle react-query is built upon usually leads to a better ux if you keep showing stale data instead of a loading spinner while background updates are happening. otherwi…