-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix bug where onCompleted and onError are stale for useMutation. onCompleted and onError could not be changed while a mutation is executing. #9740
Conversation
@charle692: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
@@ -710,6 +770,68 @@ describe('useMutation Hook', () => { | |||
expect(onCompleted1).toHaveBeenCalledTimes(1); | |||
expect(onCompleted1).toHaveBeenCalledWith(CREATE_TODO_DATA); | |||
}); | |||
|
|||
it('should allow updating onCompleted while mutation is executing', async () => { |
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.
These two specs I added specifically fail without this change, with the change pass. So hopefully this should prevent the issue from being re-introduced.
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.
I took a look at this. I am confirming that the tests fail when using baseOptions
(see attached image). @charle692 Thank you so much for tracking down the stale callback issue, writing tests! I’m really sorry that I introduced this bug and I really appreciate you fixing it.
@charle692 If you want to rebase this branch against the latest |
Sorry about that, I have a vscode extension that keeps adding that in. I think that you removed it already but I'll double check and remove. At minimum I'll rebase with main to get this up to date. |
@brainkim no worries at all :) just trying to help out anyway I can! Thanks for taking a look at this so quickly, both of you. |
9e9f966
to
d5d12bf
Compare
…mpleted and onError could not be changed while a mutation is being executed. Delete .dccache
d5d12bf
to
343f051
Compare
@benjamn I reverted the changes you made attempting to use the merged options. Firstly, it would be incorrect insofar as the @charle692 Thank you again and congratulations on the PR. I really do appreciate the time and effort you put into fixing this. Unrelatedly, there are batch link tests which are failing 😭 |
@charle692 @brainkim These changes are available now if you run |
No worries, after looking at the specs that were failing I can agree with what you are saying. That if we use clientOptions, and Anyways, thanks to both of you for taking a look at this and getting it merged, really appreciate it :). |
fixes #9714
fixes #9493
Related to #9111
Since 3.5.0 there's been a bug with the
useMutation
hook from this PR that has been preventing us from upgrading to the latest version.Currently,
onCompleted
andonError
are stale and cannot be updated while a mutation is executing. See here for example on how to reproduce this issue.The reason for this is that
useMutation
invokesonCompleted
andonError
viabaseOptions
rather than directly from theref.current
. Due to this, it doesn't have the latest copy of the callbacks once the operation is complete.Checklist: