Apollo-client: Nested queries cause resetStore to throw 'Store reset while query was in flight'

Created on 7 Jun 2018  ·  5Comments  ·  Source: apollographql/apollo-client

The problem

apollo.resetStore() hangs forever on the second time it's called and throws Store reset while query was in flight(not completed in link chain) errors on successive calls.

Screenshot

It might be related to https://github.com/apollographql/apollo-client/issues/2919

Demo

live: https://resetstore-bug-khorpkwmii.now.sh
source: https://github.com/zvictor/bug-resetStore

Steps to reproduce

  1. Open https://resetstore-bug-khorpkwmii.now.sh or run https://github.com/zvictor/bug-resetStore locally.
  2. Login (you can use [email protected] as both email and pass 😉)
  3. Logout. The logs will contain only 3 entries, instead of 4:

    • resetStore started

    • resetStore finished

    • resetStore started

  4. Login again. The Store reset while query was in flight(not completed in link chain) error will be thrown.
  5. You can try reloading the page and then restart the process, now logged in. The same behaviour will be seen.

Considerations

  • Commenting out Network at components/MeBox.js:39 makes the bug disappear.

  • This issue only occurs when there are nested queries in the page.
    The MeBox component contains a Query that will render the Network component once the user data is loaded. Inside Network there is also a Query, and that seems to be the origin of the error.


Versions
System:
OS: macOS High Sierra 10.13.4
Binaries:
Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.1.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
Browsers:
Chrome: 66.0.3359.181
Safari: 11.1
npmPackages:
apollo-boost: ^0.1.7 => 0.1.7
apollo-link-context: ^1.0.8 => 1.0.8
react-apollo: ^2.1.4 => 2.1.4

✔ confirmed 🐞 bug

Most helpful comment

Here's a workaround I've found:

client.cache.reset();
await client.reFetchObservableQueries();

Unfortunately neither of these functions are documented so I don't feel comfortable depending on this long-term. I also wonder what would happen if you ran this while there actually _were_ queries in flight. Probably a nasty race condition, but still better than the current behavior of just failing with an error if there are nested queries anywhere on the page.

I'd also like to hear an update on the status of this, as it's been four months since the last official comment and this one just cost me half a day of work...

All 5 comments

I am also seeing this issue ...

@hwillson - Hi there. Is there an expected date for this to be fixed? or is there any workaround for now?

Thanks

Here's a workaround I've found:

client.cache.reset();
await client.reFetchObservableQueries();

Unfortunately neither of these functions are documented so I don't feel comfortable depending on this long-term. I also wonder what would happen if you ran this while there actually _were_ queries in flight. Probably a nasty race condition, but still better than the current behavior of just failing with an error if there are nested queries anywhere on the page.

I'd also like to hear an update on the status of this, as it's been four months since the last official comment and this one just cost me half a day of work...

Thanks for reporting this. There hasn't been any activity here in quite some time, so we'll close this issue for now. If this is still a problem (using a modern version of Apollo Client), please let us know. Thanks!

Was this page helpful?
0 / 5 - 0 ratings