-
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
Background query still active after component unmounted #11649
Comments
That is kinda expected/intended behaviour.
If you don't attach to it in a You'll see in your demo that once you add a We have to solve it this way (with the |
Thank you for your answer! I hadn't seen this option ( That's the problem I'm facing, my child component that reads the reference doesn't have time to mount. But wouldn't it be a good idea, for performance reasons, to unsubscribe the subscription if the component that called the background query is unmounted and the reference hasn't been read? |
@PiR1 I'm fairly confident this is related to #11438. An optimization we made in 3.9 with regards to background queries/query refs is what @phryneas described above, which is that if a The work in #11438 however did remove the detection of the background query unmounting. If I try this with 3.8.10 for example, I see the problem you're describing disappear. Let me think through this a bit more. I stand by that change as I believe it is generally a positive one. But you have a good point about not keeping that subscription around when |
I've got a failing test that demonstrates this issue: #11651. This also occurs when changing variables on I tried a couple quick ideas without luck. I think this is going to require a bit more thought to try and nail all the cases down here and work well with strict mode. If you've got ideas and would like to contribute, feel free to use the tests in my PR as a base 🙂 |
Thank you for the update! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
When you have a component with a background query that have been unmounted, the background query is still active. So if you modify the cache corresponding to the queried objects, the background query is triggered and a request is sent to the server.
Link to Reproduction
https://codesandbox.io/p/github/PiR1/react-apollo-error-template/main?import=true
Reproduction Steps
Step to reproduce the issue (on the above codesandbox)
General step to reproduce the issue
@apollo/client
version3.9.6
The text was updated successfully, but these errors were encountered: