-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
testing-library/react causes infinite loops on query unless onCompleted is wrapped in a useCallback #7690
Comments
@ynotdraw This kind of problem should have been fixed by #6588. When I update the |
Hey @benjamn , thanks for your time and the response! Here's what I'm seeing with ✗ yarn why @wry/equality
yarn why v1.22.5
[1/4] 🤔 Why do we have the module "@wry/equality"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "@wry/[email protected]"
info Reasons this module exists
- "@apollo#client" depends on it
- Hoisted from "@apollo#client#@wry#equality"
info Disk size without dependencies: "172KB"
info Disk size with unique dependencies: "240KB"
info Disk size with transitive dependencies: "240KB"
info Number of shared dependencies: 1
=> Found "@types/apollo-upload-client#@wry/[email protected]"
info Reasons this module exists
- "@types#apollo-upload-client#@apollo#client" depends on it
- Hoisted from "@types#apollo-upload-client#@apollo#client#@wry#equality"
info Disk size without dependencies: "76KB"
info Disk size with unique dependencies: "144KB"
info Disk size with transitive dependencies: "144KB"
info Number of shared dependencies: 1
=> Found "apollo-utilities#@wry/[email protected]"
info This module exists because "@lifeomic#graphql-tools-cli#graphql-tools#apollo-utilities" depends on it.
info Disk size without dependencies: "68KB"
info Disk size with unique dependencies: "136KB"
info Disk size with transitive dependencies: "136KB"
info Number of shared dependencies: 1
✨ Done in 0.92s. It appears I have three different versions, due to three different dependencies requiring the different versions. I'm starting to wonder if that is the root cause of the issue? I can see if I can create a reproduction in the code sandbox with |
If you can update to If all else fails, since you're using yarn, you might be able to solve this version conflict using their resolutions feature, since Although I hope |
EDIT: Never mind this. I forgot the step to wrap my app with ApolloProvider. When I did that, it worked as intended :)
(first off, I'm new to ApolloClient and GraphQL so please my lack of knowledge :) ) I've checked that I have the updated libs as suggested above. however, I cannot use useQuery() as in the documentation examples as it will run an infinitive loop This will just run logs to the console forever until I stop the server
if this is not the correct way of using useQuery() maybe the docs should be updated? |
Let us know if this is still a concern with |
Intended outcome:
Given the following query:
The component continually re-renders,
onCompleted
is never called, andloading
is alwaystrue
.This issue is pretty well documented on #6301; however, the solution mentioned in the comments is to wrap
onCompleted
in auseCallback
.I'm more or less wondering if this is an acceptable solution from the Apollo Client team or if there's something that can be done in the client itself to resolve.
Actual outcome:
The component continually renders, never firing the
onCompleted
and always having theloading
prop from the query as true.How to reproduce the issue:
It appears this code sandbox is still valid in regards to an app hitting this issue: https://codesandbox.io/s/sleepy-mendeleev-1q9jf?file=/src/App.js. My specific use-case is only seeing this behavior in a test environment. If this would be helpful to reproduce via a code sandbox, I'll gladly spin one up if the original link here is not helpful at all.
Versions
The text was updated successfully, but these errors were encountered: