Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

State update on unmounted component after Apollo cache update #3941

Open
tkvlnk opened this issue Apr 19, 2020 · 5 comments
Open

State update on unmounted component after Apollo cache update #3941

tkvlnk opened this issue Apr 19, 2020 · 5 comments

Comments

@tkvlnk
Copy link

tkvlnk commented Apr 19, 2020

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

@msheakoski
Copy link

msheakoski commented Jun 2, 2020

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.

@jvrbnjak89
Copy link

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.

@tkvlnk
Copy link
Author

tkvlnk commented Jun 2, 2020

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

@jvrbnjak89
Copy link

Then I think you'll have to wait for this apollo-client fix.
apollographql/apollo-client/pull/6216

@msheakoski
Copy link

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants