-
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
Fix issue where a query may not stop polling after unmount when in Strict mode with cache-and-network
fetch policy
#11837
Conversation
… doesn't have a poll interval
🦋 Changeset detectedLatest commit: 75bce0d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
/release:pr |
size-limit report 📦
|
A new release has been made for this PR. You can install it with:
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
a61042c
to
c9bdf40
Compare
@@ -781,7 +781,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`, | |||
options: { pollInterval }, | |||
} = this; | |||
|
|||
if (!pollInterval) { | |||
if (!pollInterval || !this.hasObservers()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that polling is started correctly in all cases now, even if a subscription starts delayed?
Ah, it is called from reobserveAsConcast
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Thats when this polling would kick in. When the component unmounted, it triggered a broadcast, which ended up calling this updatePolling
function and starting a new poll interval from the observable that wasn't subscribed to.
Fixes #9431
Fixes #11750
When using
useQuery
in React's strict mode, 2ObservableQuery
instances are created due to how React's strict mode works with refs and rendering the component twice. The 2ObservableQuery
objects are created because theuseInternalState
hook runs twice in strict mode and theref.current
property is not set until after the component renders the second time. Because of this, a cache broadcast would happen on teardown of the 2nd observable query (the one actually used byuseQuery
) and this would cause the 1st observable query to start polling itself because it was never torn down.This change updates the
updatePolling
function to only run polling if there are active subscribers to theObservableQuery
.