Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clearStore causes a crash when there is an active query #11846

Open
ach5910 opened this issue May 15, 2024 · 3 comments
Open

clearStore causes a crash when there is an active query #11846

ach5910 opened this issue May 15, 2024 · 3 comments

Comments

@ach5910
Copy link

ach5910 commented May 15, 2024

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

  • apollo3-cache-persist@0.14.1
  • apollo-link-token-refresh@0.6.1
  • @muchobien/apollo-persistence-mapper@npm:^1.0.0
  • apollo-link-sentry@3.3.0

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

@bignimbus
Copy link
Contributor

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

@Nehal-Zeller
Copy link

Nehal-Zeller commented May 23, 2024

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

@ach5910
Copy link
Author

ach5910 commented May 24, 2024

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

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

No branches or pull requests

3 participants