apollo-client: `onComplete` not being called after doing a refetch
Issue Description
After an investigation we found out that refetching (using refetch, polling, fetchMore) is not working properly in combination with the onComplete
method. On version 3.7.17 it did, in the sense that onComplete
was called when a refetch was done. On version 3.8.0 (but also 3.8.1) the onComplete
method doesn’t get called anymore after a refetch was done. This problem occurs for refetch
but also using pollInterval
, fetchMore
and perhaps other methods that are refetching data.
Link to Reproduction
https://codesandbox.io/p/sandbox/cool-paper-l7wlk2
Reproduction Steps
We’ve created reproductions in the codesandbox, that shows the problems between the Apollo client versions.
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 15
- Comments: 15 (6 by maintainers)
Can confirm - this is a bug that seems to be introduced with 3.8. Reverting back to 3.7.17 fixes it for us.
I’ve noticed this behavior in 3.8 too and I agree it should be mentioned in the docs
@bignimbus thanks for your quick response 💯
I’ve added the
APOLLO_URI
const inapolloClient.js
, there you need to put the url of your sandbox, then it should work.notifyOnNetworkStatusChange: true
does work for now indeed, it’s also what we’re using in production for the time being.If this is the way to go, I think it would be nice to clarify this in the docs maybe or mention it somewhere in the release notes 😄
Thanks for your help!
We have a similar issue after updating to 3.8 but only with a unit test
We have something like this:
When running the tests
onCompleted
is never called butdata
is populated correctly so I think the mocks andMockProvider
are set up correctly.If I remove the
fetchPolicy
or even change thefetchPolicy
tocache-and-network
thenonCompleted
gets called.Any idea why this might be happening?
Thanks all - I’m currently on mobile but will take a closer look once I’m at my laptop. We can definitely call this out in the docs 👍
Also confirming this is a bug that I’ve encountered when upgrading to 3.8. Gonna stay with 3.7.
Thanks all, looking forward to making these updates. @av-k I appreciate the cross-link of the issue. Some feedback: I’m sure your comment was meant to be helpful but it could be interpreted as calling a maintainer out in a way that I’m hoping you didn’t intend, just wanted to make you aware 🙏🏻