apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.38k stars 2.66k forks source link

Calling `clearStore` while a lazyQuery is pending causes an error #11988

Closed phryneas closed 3 months ago

phryneas commented 3 months ago

Hey @jerelmiller, I get the same error stack trace error in node_modules/@apollo/client/react/hooks/useQuery.js

To reproduce the issue, go to search in the sandbox preview and press "OK" to reproduce the bug. I ran a lazy query and then quickly performed clearStore() in /src/components/Search.js to simulate it.

CodeSandbox

Thanks for looking into it!

Originally posted by @DerekWang98 in https://github.com/apollographql/apollo-client/issues/11846#issuecomment-2268178980

phryneas commented 3 months ago

In the codesandbox we see a race condition here:

https://github.com/apollographql/apollo-client/blob/c210a03004f7a37db41b48f1ea74ab44602ef10f/src/react/hooks/useLazyQuery.ts#L226-L255

complete is called before next was called, so result remains undefined.

The question is how to best act on this:

We need to discuss this internally. Putting it on the agenda for our next meeting.

github-actions[bot] commented 3 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

github-actions[bot] commented 2 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.