apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

clearStore causes a crash when there is an active query

Open ach5910 opened this issue 9 months ago • 3 comments

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.

Screenshot 2024-05-15 at 9 05 37 AM

I am using

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

ach5910 avatar May 15 '24 13:05 ach5910

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)?

bignimbus avatar May 15 '24 13:05 bignimbus

Facing the same error, is there any way we can kill all pending active queries other than clearStore?

Nehal-Zeller avatar May 23 '24 15:05 Nehal-Zeller

@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!

ach5910 avatar May 24 '24 00:05 ach5910