client.stop is not the way to prevent "reset store when query is in flight error"
See original GitHub issueThis is probably a documentation issue or might be considered an edge case. When you reset the cache, you often get the error:
Store reset while query was in flight (not completed in link chain)
My solution was to call client.stop()
before resetting the store. However, after that, the local cache doesn’t work anymore. It probably requires a full client recreation? Or is this considered a bug.
Intended outcome:
The pattern to correctly reset the store should be clear.
Actual outcome:
It’s not clear how to reset the store and avoid the error.
How to reproduce the issue:
I’ve created an example that reproduces the various cases.
https://codesandbox.io/s/quirky-haslett-db3vj?file=/src/index.js
Versions @apollo/client 3.0.0-beta.48
System: OS: macOS Mojave 10.14.6 Binaries: Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.1/bin/yarn npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm Browsers: Chrome: 81.0.4044.138 Safari: 13.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Thanks for the reproduction @mschipperheyn.
ApolloClient.stop()
is intended to be called just before destroying the client instance, which explains why the cache stops working. Although this method is public, you shouldn’t really ever have to call it yourself (it’s more for libraries that integrate with Apollo Client that need a way to ensure theQueryManager
has been stopped). If you’re usingstop
then yes you’ll likely have to reinstantiate the client instance.That being said, the
Store reset while query was in flight (not completed in link chain)
can definitely be annoying to deal with. We’ll put some thought into a way to improve this.Found this thread after spending so many hours digging. The error message in the title wasn’t correct, so google couldn’t pick up. The actual error is “Store reset while query is in flight”. Therefore, I’m adding this comment in hope of making this thread SEO friendly.