client.resetStore() does not refetch in-flight queries
See original GitHub issueThank you for the great product! I love how easy Apollo Client makes it to bind remote state into my React application.
I’m having a small issue with how client.resetStore()
functions with regards to in-flight queries:
Intended outcome:
When client.resetStore()
is called, it should be assumed that the application state has fundamentally changed in a way that makes the results of all previous queries stale. The documentation suggests that this is the case:
The easiest way to ensure that the UI and store state reflects the current user’s permissions is to call
client.resetStore()
Actual outcome:
client.resetStore()
refetches returned queries, but not currently in-flight queries.
This means that it doesn’t work as a means to clear out stale application state after the state of the application has fundamentally changed (i.e. after login or logout).
Furthermore, this presents a risk of “leaking” information after logout via the Apollo cache. For example:
logout();
// Clear the Apollo cache to clear any cached sensitive information
await client.resetStore();
If a getSensitiveInformation
query were in-flight at this time using authorization available at query-time but unavailable after logout, then the user will continue to see that state even after logout.
How to reproduce the issue: I’ve created a code sandbox to reproduce the issue here. In that code sandbox, there’s also a link to a Loom video where the issue is reproduced.
Suggested fix:
client.resetStore()
should clear the cache for returned queries and in-flight queries. Maybe the results of any in-flight queries should be ignored, also? (i.e. they shouldn’t transition their corresponding useQuery
loading
status until the query launched by client.resetStore()
has returned). I’m less sure on the correct behavior here.
Versions
❯ npx envinfo@latest --preset apollo
npx: installed 1 in 1.486s
System:
OS: macOS 10.15.7
Binaries:
Node: 12.13.0 - ~/.asdf/installs/nodejs/12.13.0/bin/node
Yarn: 1.22.4 - ~/.asdf/installs/nodejs/12.13.0/.npm/bin/yarn
npm: 6.12.0 - ~/.asdf/installs/nodejs/12.13.0/bin/npm
Browsers:
Chrome: 87.0.4280.141
Safari: 14.0.1
npmPackages:
@apollo/client: 3.3.6 => 3.3.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top GitHub Comments
Would still love to see this get resolved 👍
No,
I’m asking about reactive variables as state management:
https://www.apollographql.com/docs/react/local-state/reactive-variables/