The onCompleted callback of the useQuery hook executes on data mutations
See original GitHub issueIntended outcome:
The onCompleted
callback in the useQuery
hook shouldn’t be executed when data has changed by a mutation. The callback function needs to be called only once, after the data has been fetched.
Actual outcome:
The onCompleted
callback of the useQuery
hook executes on each data change.
How to reproduce the issue: https://codesandbox.io/s/mutations-oncompleted-callback-execution-2n2yic?file=/src/index.js
- Add a todo
- Update the todo
Switch between @apollo/client
versions to see the behavior of the onCompleted
callback varies between 3.4.x
and 3.5.x
, 3.6.x
versions.
On version 3.4.x
, the onCompleted
callback is called only once, when data fetches, while on versions 3.5.x
and 3.6.x
, the callback is executed two times, when data fetches and additionally after the mutation.
Versions
3.4.14
: works as expected.
3.5.x
and 3.6.x
: the onCompleted
callback of the useQuery
hook executes on data mutations.
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:7 (4 by maintainers)
Top GitHub Comments
Appreciate the reproduction here, @krasai! I have https://github.com/apollographql/apollo-client/pull/10229 open with the fix, I’ll update this issue again when it’s merged and released. Thanks everyone 🙇♀️
The fix is now available in the current 3.8
alpha
release which can be installed vianpm i @apollo/client@alpha
.