-
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
Query is not cleaned up after component is unmounted in afterware #1319
Comments
As of If I remember correctly this had the side-effect of making it difficult to for you to call |
@calebmer oh, in that case it seems I've not managed to reproduce the error I had in my real app. Since downgrading my reproduction repos solves it indeed, which is not the case for my real app. Also, invoking resetStore seems to work pretty good in the repo I linked above. The difficulty with I need to dig deeper and try to isolate what I do differently in the real app. |
Still haven't manage to reproduce in the error-template project. But I noticed that if you add a EDIT This commit reproduces the recursive refetch issue describe above in the react-apollo-error-template: jacobk/react-apollo-error-template@1f2fd60 I will continue to investigate and narrow in on my initial problem but the above is probably worth looking in to. |
The last version of https://github.com/jacobk/react-apollo-error-template is probably the same issue I'm seeing. The difference is that I don't invoke |
@calebmer I think the current issue might be this empty subscribe in react-apollo: https://github.com/apollographql/react-apollo/blame/master/src/graphql.tsx#L642 When the wrapped react component unmounts the empty observer added when recyling causes https://github.com/apollographql/apollo-client/blob/master/src/core/ObservableQuery.ts#L439-L441 to not teardown the query and hence it will refetch on What is that subscribe needed for? |
I was playing around with the new fetchPolicy and doing observableQuery.setOptions({
fetchPolicy: 'cache-only'
}); before saving the query in the recycler seems to fix the issue. It would probably make sense to store the old policy for when its reused. |
@jacobk the reason we have that subscribe is so that |
@calebmer thanks for the answer! I guess it's fair to assume that it's an unwanted side effect to also have the recycled queries be refetched when resetting the store. This is part react-apollo and part apollo-client. I think my proposal with changing the fetchPolicy for recycled queries seems sensible for react-apollo but I'm not sure what other side effects it might have? Regarding apollo-client I think I'm not alone in not fully understanding the intentions behind |
That was the point behind Want to submit a PR to |
I just wanted to add to the discussion that a working I like the mutation approach taken by GraphQL, making it possible for the client to update only data that has changed. However, there are situations where a lot of data is modified as a result of a mutation. Including all this data in the mutation response quickly becomes a pain in the ass. In many cases it is acceptable for the client empty the cache and refetch all active queries as a result of a successful mutation ( Im currently working on an app using Relay and looking into Apollo as Relay in its current state offers very little support for "manually" manipulating the store. In addition to this the performance of Relay is terrible when a large amount of data is refetched ( |
Ok I think / hope this is now conclusively fixed with the |
Intended outcome:
Queries should be removed when a component is unmounted as a result from logic in afterwares.
See #1195
Actual outcome:
Query is lingering in apollo-client after component is unmounted.
How to reproduce the issue:
npm install
npm start
Demo
The text was updated successfully, but these errors were encountered: