-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
useSuspenseQueries made extra requests after fetching data #6491
Comments
There is likely a problem with how we setup query/packages/react-query/src/suspense.ts Lines 24 to 30 in e7f6d3a
to a avoid a refetch-on-mount here. However, with Your example though is flawed. You only see two useEffect calls because of Here's a fork with what I mean.
The log output I'm seeing is:
This is exactly because of the
However, I don't really know how we can reliably prevent a refetch on the first mount after the query has suspended :( |
I think the best we can do right now is document that you should probably set a high enough staleTime so that queries won't refetchOnMount when the suspended component re-mounts when using |
Thanks for the explanation! I've created the following PR to update the docs: #6641 |
we've documented the workaround, which is good enough right now imo. |
Describe the bug
useSuspenseQueries
will request data again right after receiving a response. As a side effect, this causes the result ofuseSuspenseQueries
to change, which will triggeruseEffects
unnecessarily and under the right conditions, infinite query requesting.Your minimal, reproducible example
https://codesandbox.io/p/sandbox/tanstack-query-bug-forked-gzjkr9?file=%2Fsrc%2FApp.js%3A30%2C56
Steps to reproduce
useSuspenseQueries
and mock multiple requests with promises and setTimeoutExpected behavior
I expect the data request to happen once.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: MacOS
Browser: Chrome
Version: 119.0.6045.199
Tanstack Query adapter
react-query
TanStack Query version
5.12.2
TypeScript version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: