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

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

Closed
phryneas opened this issue Aug 5, 2024 · 3 comments · Fixed by #11989
Closed

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

phryneas opened this issue Aug 5, 2024 · 3 comments · Fixed by #11989

Comments

@phryneas
Copy link
Member

phryneas commented Aug 5, 2024

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 #11846 (comment)

@phryneas
Copy link
Member Author

phryneas commented Aug 5, 2024

In the codesandbox we see a race condition here:

return new Promise<
Omit<QueryResult<TData, TVariables>, (typeof EAGER_METHODS)[number]>
>((resolve) => {
let result: ApolloQueryResult<TData>;
// Subscribe to the concast independently of the ObservableQuery in case
// the component gets unmounted before the promise resolves. This prevents
// the concast from terminating early and resolving with `undefined` when
// there are no more subscribers for the concast.
concast.subscribe({
next: (value) => {
result = value;
},
error: () => {
resolve(
toQueryResult(
observable.getCurrentResult(),
resultData.previousData,
observable,
client
)
);
},
complete: () => {
resolve(
toQueryResult(result, resultData.previousData, observable, client)
);
},
});
});

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

The question is how to best act on this:

  • resolving this seems wrong as the user might expect data
  • rejecting might be unexpected
  • doing nothing might lead to a memory leak

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

Copy link
Contributor

github-actions bot commented Aug 6, 2024

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.

Copy link
Contributor

github-actions bot commented Sep 6, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant