react-apollo
react-apollo copied to clipboard
State update on unmounted component after Apollo cache update
Intended behavior: useQuery
checks if component is unmounted at the moment when the setState
is fired and skips state update on cache update
Actual behavior: When "parent" component and "child" components both listen for same query. And at some point due to the cache update for that listened query "child" should unmount the warning about update of state for unmounted component is fired.
Steps to reporoduce: Codesanbox link
I experience this too. I have been trying to figure out how to get rid of the message and so far, the only thing that worked was to set fetchPolicy: "no-cache"
, but that slows everything down.
I though that maybe #3139 fixed it, but it only seems to affect subscriptions.
Check this comment from the #3635
I managed to sort this out by replacing the useQuery hook with the useLazyQuery and calling it from the useEffect. Hope that will work for you as well.
Check this comment from the #3635
I managed to sort this out by replacing the useQuery hook with the useLazyQuery and calling it from the useEffect. Hope that will work for you as well.
yeah I know about this workaround but it would be better to have a clean way without redundant tricks
Then I think you'll have to wait for this apollo-client fix. apollographql/apollo-client/pull/6216
Thank you, @jvrbnjak89. It looks like a fix is close to being released, so I will wait for that, but I appreciate the further insight into the issue that you provided!