-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define when suspense queries should be refetched and when they should throw #1059
Comments
Can't remember what I changed, but is this example working for you as expected? https://codesandbox.io/s/ping-pong-react-query-client-forked-pbc4e?file=/src/components/Demo.js |
@tannerlinsley thanks for the really quick reply! I had the same problem - maybe I'm not doing a good job of illustrating. When I navigate back to Page 1 from Page 2, you'll notice that the Query stays in an Inactive state: I was expecting it to re-fetch this query when the component re-mounts. |
I think that would require the query to suspend if it is in the |
Think there are two issues here:
|
Yep I think you’re right on both counts
Tanner Linsley
…On Sep 19, 2020, 11:17 AM -0600, Niek Bosch ***@***.***>, wrote:
Think there are two issues here:
1. Devtools is not notified when observers unsubscribe (if you reselect the query then it shows the correct state).
2. There is some specific code to prevent refetching when suspense is enabled. This is probably to prevent double fetches because the default stale time is 0 and the hook does not know if it is rendering right after a suspense or after some page switch. Unfortunately this means suspended queries are never refetched. Is my assumption correct @tannerlinsley ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I think we need to define the behavior when using suspense. Currently it will only trigger suspense when it is loading for the first time. Any additional mounts will not trigger a refetch, which does not sound desirable. Maybe we should set a default stale time when suspense is enabled? Then the query will at least be refetched again if it re-mounts after some time. Then the other question is, when do we want to trigger suspense? Only on first load, or also on refetches? Or does it need to be configureable? |
I'm pretty sure that once |
The main problem is that when a component is mounted, it starts a fetch, and because of the way suspense works, the component immediately gets unmounted. When the fetch is complete, the component will mount again, but because the default stale time is 0, it will trigger another fetch because the data is already considered stale. The double fetching is something we want to avoid. Currently I can think of these solutions:
Besides this issue, if users also want to use suspend when refetching, maybe we should add a |
#1 sounds like the fastest way forward for now. In previous versions of RQ, we had some mutable properties on the query itself that would allow observers to detect if the last fetch was because of a suspension, and thus not trigger the fetch again on mount. I wonder if that same idea could work better now that the observers have become a bit smarter. |
Just found out this issue. I'm working on react-native project with react-query. Adding stale time doesn't trigger a new invokation of useQuery when a component is already suspended once :/ |
@tannerlinsley any plan to fix this issue, I think this issue just block the use of suspense with react-query, as the query will never invalidate, that breaks the SWR(stale while revalidate) which is the biggest benefit of react-query think about it, you have a query in one page, and then navigate to another page, the query should get invalidate and send a request again, but it doesn't when suspense enabled |
Our current workaround in Blitz is to call |
Is anyone still having trouble with suspense in v3? |
I haven't had a chance to try v3 yet |
I tried it's fixed in V3 |
I faced the issue #1582 in version I built a simple demo in Code Sandbox where it is possible to reproduce it. Any plans to have it fixed? |
Is this the same as #2367? |
Describe the bug
When a user does client-side navigation to return to a previously visited page (react-router-dom), the useQuery hook is not invoked again, even if the query has been marked as invalid. This is an issue because the server value could change in a different browser session or device and the useQuery data value would no longer be in sync.
To Reproduce
Created a reproducible environment for testing the bug here:
https://codesandbox.io/s/ping-pong-react-query-client-guqhn
Important files: src/index.js and src/components/Demo.js
Steps to reproduce the behavior:
-- https://1675g.sse.codesandbox.io/ping-increase
Expected behavior
On return to Page 1 from Page 2, I would expect the useQuery hook to fetch the latest server value.
The text was updated successfully, but these errors were encountered: