Skip to content

Ensure pollInterval is applied to useLazyQuery when it changes between renders#13248

Open
jerelmiller wants to merge 4 commits into
mainfrom
jerel/use-lazy-query-poll-interval
Open

Ensure pollInterval is applied to useLazyQuery when it changes between renders#13248
jerelmiller wants to merge 4 commits into
mainfrom
jerel/use-lazy-query-poll-interval

Conversation

@jerelmiller
Copy link
Copy Markdown
Member

@jerelmiller jerelmiller commented May 29, 2026

Fixes #12832

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where polling interval changes were not applied when the component rerendered, ensuring polling continues with the updated interval settings.

Review Change Stack

@jerelmiller jerelmiller requested a review from phryneas May 29, 2026 22:10
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 659440c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 535cce97-1746-4a26-b061-2d8b0760c9d4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR fixes a bug where useLazyQuery does not apply updated pollInterval values across component rerenders. The fix adds pollInterval to the options synced by the effect and its dependency list, with comprehensive test coverage validating polling transitions and interval updates.

Changes

useLazyQuery pollInterval sync

Layer / File(s) Summary
Implementation fix and test coverage
src/react/hooks/useLazyQuery.ts, src/react/hooks/__tests__/useLazyQuery/polling.test.tsx
useLazyQuery now passes options?.pollInterval to updatedOptions and includes it in the useEffect dependency list. Test validates initial polling, state transitions across loading/networkStatus, rerendering with updated pollInterval (100) and continued polling, then rerendering with pollInterval: 0 to stop polling.
Release documentation
.changeset/honest-terms-eat.md
Changeset entry documents a patch release for @apollo/client fixing useLazyQuery to apply changed pollInterval between renders.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

auto-cleanup

Suggested reviewers

  • phryneas

Poem

A lazy query's poll was stuck in place,
Till now—pollInterval finds its grace!
Rerender swift, the timing flows anew,
Zero halts the dance; the fix rings true. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: ensuring pollInterval is applied to useLazyQuery when it changes between renders, which aligns with the core fix in the changeset.
Linked Issues check ✅ Passed The PR implements the fix for issue #12832 by adding pollInterval to dependency tracking and options application in useLazyQuery, with comprehensive test coverage matching the expected behavior from the linked issue.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the pollInterval issue in useLazyQuery: test file, implementation, and changeset documentation are all aligned with the linked issue requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jerelmiller jerelmiller changed the title Ensure Ensure pollInterval is applied to useLazyQuery when it changes between renders May 29, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/react/hooks/useLazyQuery.ts (1)

559-594: 💤 Low value

Prefer stableOptions?.pollInterval for consistency; the extra dep is redundant.

pollInterval is a primitive number, not an inline function. The separate options?.* reads (and the explicit deps) exist specifically because @wry/equality doesn't compare function identity, so stableOptions misses inline-function changes — that rationale doesn't apply here. useDeepMemo already detects primitive changes, so reading from stableOptions?.pollInterval works and re-runs the effect via the existing stableOptions dependency, matching the other primitive options (errorPolicy, returnPartialData, etc.). Adding options?.pollInterval to the dependency list is then redundant.

♻️ Align with the primitive-option pattern
         nextFetchPolicy: options?.nextFetchPolicy,
         skipPollAttempt: options?.skipPollAttempt,
-        pollInterval: options?.pollInterval,
+        pollInterval: stableOptions?.pollInterval,
       };
     options?.nextFetchPolicy,
     options?.skipPollAttempt,
-    options?.pollInterval,
   ]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/react/hooks/useLazyQuery.ts` around lines 559 - 594, The effect's
dependency list includes options?.pollInterval redundantly; change that
dependency to stableOptions?.pollInterval so the effect consistently depends on
the stabilized primitive like the other primitive options (e.g. errorPolicy,
returnPartialData). In the React.useEffect block that builds updatedOptions and
calls observable.applyOptions(updatedOptions), replace options?.pollInterval in
the dependency array with stableOptions?.pollInterval (keeping the other deps
unchanged) so the effect reruns via stableOptions and removes the unnecessary
options dependency.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/react/hooks/useLazyQuery.ts`:
- Around line 559-594: The effect's dependency list includes
options?.pollInterval redundantly; change that dependency to
stableOptions?.pollInterval so the effect consistently depends on the stabilized
primitive like the other primitive options (e.g. errorPolicy,
returnPartialData). In the React.useEffect block that builds updatedOptions and
calls observable.applyOptions(updatedOptions), replace options?.pollInterval in
the dependency array with stableOptions?.pollInterval (keeping the other deps
unchanged) so the effect reruns via stableOptions and removes the unnecessary
options dependency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 0bc1f553-d1c1-4289-a8a6-b160bb628503

📥 Commits

Reviewing files that changed from the base of the PR and between 189d166 and fe806eb.

📒 Files selected for processing (3)
  • .changeset/honest-terms-eat.md
  • src/react/hooks/__tests__/useLazyQuery/polling.test.tsx
  • src/react/hooks/useLazyQuery.ts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@13248

commit: 659440c

@jerelmiller jerelmiller requested a review from DaleSeo June 2, 2026 00:07
@apollo-librarian
Copy link
Copy Markdown
Contributor

apollo-librarian Bot commented Jun 2, 2026

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: edff3929f0d46b1fcd805c0c
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[4.0] pollInterval is not applied to useLazyQuery when it changes between renders

1 participant