-
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
Unmounting a component before a query is resolved via useLazyQuery
lets the promise resolve instead of aborting the promise.
#10698
Conversation
🦋 Changeset detectedLatest commit: 18be640 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
/release:pr |
A new release has been made for this PR. You can install it with |
useLazyQuery
let the promise resolve instead of aborting the promise.useLazyQuery
lets the promise resolve instead of aborting the promise.
…ther than aborting them when unmounting the component
… in the right resolved data.
… intended behavior
167d5f4
to
18be640
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always great to see a single PR manage to address so many issues at once 🎉🎉🎉
// Use refs to track options and the used query to ensure the `execute` | ||
// function remains referentially stable between renders. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Also not sure why Netlify is deploying in the first place (no docs changes) but it rebuilt just fine here, the PR check just isn't picking that up... |
Fixes #9755
Fixes #10174
Fixes #10198
Fixes #10520
Fixes #10533
This PR addresses a few outstanding
useLazyQuery
issues and changes the behavior introduced in #10427 when a component unmounts before a query is fully resolved.Prior to #10427, components that unmounted before the query was resolved were stuck awaiting the promise indefinitely since promise resolution was dependent on the
useQuery
render cycle to resolve the promise. #10427 attempted to fix this by aborting the promise any time the component unmounted. This change however was a bit too spicy 🌶️ . Aborting the promise also made it impossible for some use cases that relied upon promise resolution to work correctly.This PR changes the behavior so that unmounting a component will no longer cause the promise to abort, but rather let the promise resolve naturally with the result from the server. This change had a number of positive side effects that resolved a number of other issues, for example, the ability to run the execution function multiple times with different variables in parallel will now resolve each of the promises with the correct data (#9755).
This PR also makes it possible to dynamically change the query document passed to
useLazyQuery
and ensure the execute function will use the latest set document (#10198). Some additional tests were added to ensure rerendering with new variables before executing the query would use the proper option set.Checklist: