-
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
Query onCompleted callback is not called when the query data updates due to a cache update #6373
Comments
same issue heree |
@unutoiul Can you use the "emoji" button to add a "thumbs up" instead of adding a "me too" comment? That seems to be the preferred etiquette for "me too" on github these days, and makes it easier for people to count up the responses. |
This comment has been minimized.
This comment has been minimized.
@dobesv Can you confirm this codesandbox is a repro of the issue you're experiencing? https://codesandbox.io/s/compassionate-golick-5042m?file=/src/App.tsx |
@andrewnaeve It looks that way to me, yes. |
Is it possible to confirm if this is a bug or intended behaviour? On the other hand I am investigating how to perform a side-effect on the first successful network call, and not on subsequent cache updates. If this is the intended behaviour of If it is not the intended behaviour (and the behaviour will change on version bump), I will have to find alternatives. |
Is this still the expected behavior? |
Maybe related: #11526 |
When trying to upgrade from react-apollo
2.5.8
to3.1.5
we found that the behavior of theonCompleted
callback on theQuery
component had changed in a breaking manner.Intended outcome:
A
Query
componentsonCompleted
callback should be called any time the data for that Query changes, even if the change is made by another operation such as a mutation or a cache update.Actual outcome:
The
onCompleted
callback might not be called if changes are made to the cache that affect the query data.How to reproduce the issue:
I made a reproduction of this behavior in this branch here:
https://github.com/dobesv/react-apollo-error-template/tree/query-oncomplete-bug
If you open the console you will see that the
onCompleted
function logs only on the initial load, if you click the button it does not log that any more.If you rollback to the older version using
npm i [email protected]
and restart the app, clicking the button logsonCompleted
on every click.Versions
Workaround
Instead of using
onCompleted
to detect changes, you could do the same code in thechildren
render prop. This might be called more often thanonCompleted
would have been called, but in many cases it probably won't be a serious performance concern. Note that if you usesetState
in your handler you may have to add asetTimeout
and make sure you do not callsetState
again if the value hasn't changed, to avoid infinitesetState
->render
loops.The text was updated successfully, but these errors were encountered: