question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

resetStore: Store reset while query was in flight.

See original GitHub issue

Intended outcome:

resetStore without errors being thrown.

https://github.com/apollographql/apollo-client/blob/b354cf07e979def7aa0219e60dca63e8a33fa822/packages/apollo-client/src/core/QueryManager.ts#L787..L796

Actual outcome:

I’m running into an issue when calling resetStore after a logout scenario. I think I understand the reasoning, but in my case I can’t seem to find a workable way around it, and something else odd is happening:

fetchQueryPromises in snippet above is a Map, with values of {promise,reject,resolve}, so I look inside to see what they are:

const promises = Array.from(this.fetchQueryPromises.values()).map(x => x.promise)

My plan was to await Promise.all(promises) before calling resetStore, however, promises is [undefined]. For some reason, an entry is added to fetchQueryPromises without a promise, so I can’t wait for it before resetting.

The actual error Store reset while query was in flight. looks like it might not actually cause a problem, which was my main concern. But it seems like there should be a way to avoid an error being thrown.

Waiting for existing promises to complete before reset, or exposing a function to allow the user to await them before resetting seems right to me.

Is there a case for calling resetStore where a thrown error is the right outcome?

Version

  • apollo-client@^2.2.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:25
  • Comments:44 (18 by maintainers)

github_iconTop GitHub Comments

33reactions
wmertenscommented, Jul 9, 2019

Still happening on stable as of two weeks ago

30reactions
stevenkasparcommented, Apr 5, 2018

Not sure this helps anyone in this thread but I didn’t think to see if resetStore was a Promise and turns out it is. For me it was an issue of the requests that were happening right after resetStore - not the already in flight ones (I think). So changing this

cookies.set('jwt', response_data.data.getCreds.token)
this.props.client.resetStore()
this.props.loggedIn(response_data)

to this

cookies.set('jwt', response_data.data.getCreds.token)
this.props.client.resetStore().then(() => {
   this.props.loggedIn(response_data)
}) 

got rid of the error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Store reset while query was in flight (not completed in link chain)
when I log out my user. the code is const onSignout = async () => { removeToken(); client.cache.reset(); await client.resetStore(); ...
Read more >
clearStore() vs resetStore() - Help - Apollo GraphQL
resetStore () after your login or logout process has completed. This will cause the store to be cleared and all active queries to...
Read more >
"Store reset while query was in flight(not completed in link ...
"Store reset while query was in flight(not completed in link chain)" when stopQuery is called right after resetStore. Race condition?
Read more >
Javier Cuevas on Twitter: "These errors are especially bad in a ...
resetStore () where there are still queries in flight (for instance, when logging out) ... This one happens when fetchMore() is still fetching...
Read more >
Handling Errors with Apollo Client (React) - YouTube
In this video I talk about handling errors when running queries and mutations using Apollo Client in a React project.Table of contents:00:00 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found