apollo-client
apollo-client copied to clipboard
clearStore causes a crash when there is an active query
Issue Description
If client.clearStore
is called while a query response is pending, it's causing a crashing at this location https://github.com/apollographql/apollo-client/blob/main/src/react/hooks/useQuery.ts#L635.
I am using
-
[email protected]
-
[email protected]
-
@muchobien/apollo-persistence-mapper@npm:^1.0.0
-
[email protected]
and here's how I am initializing my client
persistCacheSync({
cache,
storage: new MMKVWrapper(mmkvStorage),
persistenceMapper,
trigger: "write",
debug: __DEV__,
});
const persistLink = createPersistLink();
const client = new ApolloClient({
cache,
link: from([
persistLink,
sentryBreadcrumbsLink,
retryLink,
authLink,
tokenRefreshLink,
errorLink,
httpLink,
]),
});
I've also tried using resetStore
, but I get the same error. Any feedback regarding a potential cause is greatly appreciated.
Link to Reproduction
N/A
Reproduction Steps
No response
@apollo/client
version
3.9.11
Hi @ach5910 👋🏻 thanks for letting us know! I'll chat with the team soon to see if there's anything that immediately jumps out as a bug in Apollo Client. Are you able to reproduce this issue in a clean app (e.g. without the other libraries)?
Facing the same error, is there any way we can kill all pending active queries other than clearStore?
@bignimbus Unfortunately I couldn't reproduce the bug in a sandboxed app due to the complexity of mirroring our production app's infrastructure. I know that not much help in diagnosing the problem, but I was really hoping I was missing something basic and I'd get a "RTFD" response.
@Nehal-Zeller I found a solution by calling client.cache.reset()
instead of client.clearStore()
or client.resetStore()
. I believe any active requests will update the cache if returned after resetting, but it beats having the app crash. Hope this helps!