-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
resetStore doesn't clear the cache if it was populated with cache's .restore method initially and no queries are run on the page #3539
Comments
hwillson
added a commit
that referenced
this issue
Sep 5, 2018
Merged
hwillson
added a commit
that referenced
this issue
Sep 5, 2018
* Add `clearStore` method A new `clearStore` method has been added, that will remove all data from the store. Unlike `resetStore`, it will not refetch active queries after removing store data. Fixes #2411. Fixes #2774. Fixes #3539. Fixes #3813. * Changelog update * Add `clearStore` to API docs * Add `clearStore` reference to authentication docs * Add `clearStore` reference to caching docs
#3885 adds a new |
Thank you :) |
hwillson
added a commit
that referenced
this issue
Oct 2, 2019
hwillson
added a commit
that referenced
this issue
Oct 2, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Intended outcome:
I used the client.resetStore() method to clear cache after logging out a user. I populate the cache with the data from the server initially (on page load) using the cache's .restore method, like this:
No queries or mutations happen on the page initially. When the user clicks logout, I expect apollo-client to clear the cache that I populated initially.
Actual outcome:
When the user logs out, the client.resetStore() method does not clear the data that was populated with the InMemoryCache's restore method. The cache is not cleared as the QueryManager is not initialized at the moment I call the resetStore (or the user logs out), it is initialized only when some query or mutation occurs. This is where apollo-client checks whether the QueryManager exists, and if not it skips clearing the cache:
https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/ApolloClient.ts#L402
How to reproduce the issue:
I described how to reproduce the issue in the text above. Basically, you need to init the ApolloClient with cache populated using the .restore() method. The app shouldn't fire any query or mutation on initialization, which causes
this.queryManager
to not be initialized.Versions
Binaries:
Node: 8.9.4 - /usr/local/bin/node
Yarn: 1.3.2 - /usr/local/bin/yarn
npm: 5.6.0 - /usr/local/bin/npm
npmPackages:
apollo-cache-inmemory: ^1.2.1 => 1.2.1
apollo-client: ^2.3.1 => 2.3.1
apollo-upload-client: ^8.0.0 => 8.0.0
react-apollo: ^2.1.4 => 2.1.4
The text was updated successfully, but these errors were encountered: