Skip to content
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() refetches queries that are still "active", even after those queries' components were unmounted #1560

Closed
BlooJeans opened this issue Apr 7, 2017 · 3 comments

Comments

@BlooJeans
Copy link
Contributor

I'm trying to implement logout functionality in my app, which resets / unmounts all of my views and wipes the apollo store. resetStore() wipes the store and refetches all active queries and causes problems because it refetches queries that the user is no longer authed for (as per #1552 ).

I think this is a "smaller more squashable bug" that arised from apollographql/react-apollo#462
[emphasis mine]

When a component is unmounted, instead of throwing away the ObservableQuery, we put it in a recycler to keep it alive. You can think of it like putting the ObservableQuery in the fridge to be reheated later. When a new component mounts we take our saved ObservableQuery out of the fridge, add some new options, and use the old observable query again.

Now for every container component in your app (you create one whenever you call graphql) there should only be one ObservableQuery that lives forever assuming that you only render our container component once at a time. If you render your component more than once at a time that should still be fine.

During the componentWillUnmount the component has 2 observables:

  1. the observable from the actual query
  2. when it gets unmounted, a second "empty" observable gets created (that the above PR refers to)

Because of this second observable, the query will always be considered active, thus causing it to refetch when resetStore() is called, thus causing my not-authed problem.

Intended outcome:
Unmounted components shouldnt be refetched on resetStore()

Actual outcome:
Unmounted components are refetched on resetStore()

How to reproduce the issue:
Mount a component with react-apollo, unmount it, apolloClient.resetStore()

@richardgirges
Copy link

richardgirges commented Apr 7, 2017

I've experienced the same problem. I believe this is a possible duplicate of #1319

@BlooJeans
Copy link
Contributor Author

ha, yea the recent PR (apollographql/react-apollo#531) fixed it- I was 11 hours behind the latest 😆 . Thanks for the heads up @richardgirges

@richardgirges
Copy link

haha, no problemo! Pretty stoked on this fix, been waiting for it :D

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants