-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
useQuery wrapper calls API twice #300
Comments
@pedropmedina is it possible for you to provide a minimal repo for us to reproduce the behavior? |
perhaps this is caused by react strict mode on development? https://react.dev/reference/react/StrictMode#fixing-bugs-found-by-double-rendering-in-development |
You are right @danielpza . The issue was strict mode. I'm using NextJs and turning it off got rid of the problem. However, doing so is not recommended. I'm not sure why this happens with the ts-rest wrapper and not when using react-query's native useQuery? Any thoughts? |
@pedropmedina |
I get what React is doing with strict mode @kurdin. I just don't understand why the ts-rest wrapper around react-query's userQuery is causing double fetching when this issue was already addressed by react-query's useQuery itself. In order words, using native useQuery triggers a single request while ts-rest's implementation triggers two. I think there's something in that helper that must be improved to avoid this behavior. At the end of the day, aren't we just calling native useQuery under the hood? |
You right @pedropmedina. I'll try to use ts-rest with react query to investigate this behaviour. |
Yeah, this is bizarre! We really do just return the underlying useQuery function with a provided queryFn - @michaelangelo-io any ideas or shall we write a test to investigate? |
@pedropmedina given the comments on this, TanStack/query#3492 |
That's what I was expecting @michaelangelo-io, however both request go through the network successfully as shown in the image above ^. The weird thing is that this only happens when using ts-rest wrapper. Native useQuery works as expected. |
@pedropmedina @kurdin Hi, there. I am happy to have a look if you can provide a minimal repo to reproduce the behaviour. |
I'm not sure if anyone else is experiencing this issue, but I have tried several solution and nothing works. It seems as if the useQuery wrapper makes two calls over the network. This issue is NOT present when using react-query's native useQuery hook and calling the api with the ts-rest regular client as the queryFn.
Here's what I'm seeing
The text was updated successfully, but these errors were encountered: