apollographql/apollo-client

[bug?] refetch() resolves to undefined after component is unmounted

AlexLMeow opened this issue · 0 comments

Issue Description

Async functions might end up calling refetch() after the component containing useQuery is unmounted. When this happens, await refetch() resolves to undefined, breaking any downstream code that works on the refetch result.

The typescript return value is Promise<ApolloQueryResult<TData>> so undefined is unexpected.

Seems to only occur when ApolloClient is set up with assumeImmutableResults: true.

I also have some evidence that this can occur even when the component is still mounted, but I couldn't pin down the exact scenario. Let me know if you find another trigger for this bug so i can go back and validate my application behavior accordingly.

Link to Reproduction

https://codesandbox.io/p/devbox/affectionate-pike-gx8ww7

Reproduction Steps

Click the button in the repro

@apollo/client version

My app is on ~3.4.17
Repro is on 3.9.9