Fix issue with useQuery polling when skip was initialized with true#13155
Fix issue with useQuery polling when skip was initialized with true#13155jerelmiller merged 9 commits intomainfrom
useQuery polling when skip was initialized with true#13155Conversation
🦋 Changeset detectedLatest commit: 6f30ec5 The changes in this PR will be included in the next version bump. 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 |
940cb04 to
e4aa12f
Compare
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: 46b862979f674ba00b37e40e |
commit: |
| }); | ||
|
|
||
| // https://github.com/apollographql/apollo-client/issues/13154 | ||
| it("doesn't poll when initially skipped", async () => { |
There was a problem hiding this comment.
nit: it("does not poll when initially skipped")
There was a problem hiding this comment.
@Hardanish-Singh I'm fine with it the way it is. The contraction is perfectly fine.
In the future, I'd appreciate if you didn't add these kinds of review comments. They are just noise.
I'm happy to answer specific questions or concerns you may have if you're looking at a PR, but please avoid +1 or nit comments like this. Thanks.
src/core/ObservableQuery.ts
Outdated
| !pollInterval || | ||
| !this.hasObservers() || | ||
| fetchPolicy === "cache-only" || | ||
| fetchPolicy === "standby" |
There was a problem hiding this comment.
Would it make sense to add a similar check inside of maybeFetch, too?
Currently all code paths changing any of those seem to be covered, but it seems like it could easily happen that some code path might run out of sync again.
src/core/ObservableQuery.ts
Outdated
| info.interval = pollInterval; | ||
|
|
||
| const maybeFetch = () => { | ||
| if (this.options.fetchPolicy === "standby") { |
There was a problem hiding this comment.
Actually... do we want to repeat all those other checks here, too? 😅
|
No actionable comments were generated in the recent review. 🎉 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (1)src/react/hooks/__tests__/useQuery.test.tsx (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (4)
📝 WalkthroughWalkthroughA patch fix is introduced to resolve an issue where Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
phryneas
left a comment
There was a problem hiding this comment.
one last suggestion to shave a few yaks/bytes, generally approved
Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @apollo/client@4.1.5 ### Patch Changes - [#13155](#13155) [`3ba1583`](3ba1583) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix an issue where `useQuery` would poll with `pollInterval` when `skip` was initialized to `true`. - [#13135](#13135) [`fd42142`](fd42142) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix issue where `client.query` would apply options from `defaultOptions.watchQuery`. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fixes #13154
Polling was properly skipped when changing from
skip: falsetoskip: true, but whenskipwas initialized totrue, polling kicked in.This was due to calling
updatePollingin asetTimeoutwhich runs afterreobserveis called when first subscribing toObservableQuery(which properly cancels polling when thefetchPolicyisstandby). NowupdatePollingwill also check forstandbyand cancel polling if detected.Summary by CodeRabbit
useQueryincorrectly initiating polling whenskipwas set totrueon the initial render. Polling now correctly remains inactive untilskipis disabled.