Skip to content

docs(react): add polling guide#10330

Open
Zelys-DFKH wants to merge 4 commits intoTanStack:mainfrom
Zelys-DFKH:docs/add-polling-guide
Open

docs(react): add polling guide#10330
Zelys-DFKH wants to merge 4 commits intoTanStack:mainfrom
Zelys-DFKH:docs/add-polling-guide

Conversation

@Zelys-DFKH
Copy link
Copy Markdown
Contributor

@Zelys-DFKH Zelys-DFKH commented Mar 24, 2026

Summary

  • Adds docs/framework/react/guides/polling.md — a dedicated guide for refetchInterval-based polling
  • Adds nav entry in docs/config.json between Window Focus Refetching and Disabling/Pausing Queries
  • Adds a cross-reference in important-defaults.md

Motivation

refetchInterval is one of the more commonly reached-for options but is only mentioned once in passing in important-defaults.md. There's no explanation of how it interacts with staleTime, refetchIntervalInBackground, enabled, or networkMode. The gap comes up repeatedly in Discord and on StackOverflow.

What the guide covers

  • Basic setup and why polling is independent of staleTime
  • Dynamic intervals via the function form — polling until a job finishes, for example
  • refetchIntervalInBackground for dashboards and always-on UIs
  • Disabling window-focus refetching for fullscreen game and kiosk UIs where tab focus doesn't reflect user intent, with a custom focusManager.setEventListener example
  • Pausing polling with enabled
  • networkMode: 'always' for Electron / embedded browsers where navigator.onLine is unreliable
  • Deduplication: multiple observers on the same query key don't stack their timers

Checklist

  • I have followed the steps in the Contributing guide
  • This change is docs-only (no release needed)

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive polling guide covering periodic query refresh configuration, interval function usage, pausing/resuming polling, background polling, and deduplication behavior.
    • Updated React Guides navigation to include the new polling documentation.
    • Enhanced existing React guides with cross-references directing readers to the new polling guide for related refetchInterval details.

Adds a dedicated guide for refetchInterval-based polling. The option was
only mentioned in passing in important-defaults.md with no explanation of
how it works, how to adapt it dynamically, or how it interacts with window
focus, networkMode, and the enabled flag.

Covers:
- Basic setup and independence from staleTime
- Dynamic intervals via function form
- refetchIntervalInBackground for dashboards / always-on UIs
- Disabling window-focus refetching for fullscreen game and kiosk UIs
- Pausing polling with the enabled flag
- networkMode: 'always' for unreliable navigator.onLine environments
- Deduplication behavior across multiple observers

Updates config.json to add the guide to the React sidebar between
Window Focus Refetching and Disabling/Pausing Queries.
Adds a cross-reference in important-defaults.md.
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 24, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 755a5900-04fa-4026-8b74-50e4291424a4

📥 Commits

Reviewing files that changed from the base of the PR and between 32df0e7 and 0fc4ddf.

📒 Files selected for processing (1)
  • docs/framework/react/guides/polling.md
✅ Files skipped from review due to trivial changes (1)
  • docs/framework/react/guides/polling.md

📝 Walkthrough

Walkthrough

Added a new React polling guide and updated navigation and a cross-reference: introduces documentation for refetchInterval, refetchIntervalInBackground, pause/resume patterns, network handling, and deduplication; the sidebar docs/config.json now includes a "Polling" entry.

Changes

Cohort / File(s) Summary
Navigation & Configuration
docs/config.json
Inserted a "Polling" item into the React "Guides & Concepts" navigation between "Window Focus Refetching" and "Disabling/Pausing Queries".
React Guides — Docs
docs/framework/react/guides/important-defaults.md, docs/framework/react/guides/polling.md
Added polling.md guide covering refetchInterval, function-form intervals, pause/resume behavior, refetchIntervalInBackground, network handling (networkMode), and deduplication; updated important-defaults.md to reference the new guide.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

🐰 I nibble docs where timers play,
refetch hops in bright array,
Polling whispers, steady and spry,
Queries wake and flutter by,
A joyful hop — docs amplified ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'docs(react): add polling guide' clearly and concisely summarizes the main change — adding a new polling documentation guide for React.
Description check ✅ Passed The description includes detailed sections (Summary, Motivation, What the guide covers, Checklist) that comprehensively explain the changes. However, it does not follow the required template structure with the specified 🎯 Changes and ✅ Checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/framework/react/guides/polling.md`:
- Around line 143-145: The current note incorrectly says there is "one interval
per query"; update the text to state that refetchInterval timers are scheduled
per QueryObserver (each component creates its own timer when using
refetchInterval) and that only in-flight fetches are deduplicated at the
cache/query level (i.e., duplicate network requests started at the same time are
consolidated), referencing refetchInterval and QueryObserver to make the
distinction clear. Ensure the revised wording contrasts observer-level timers
vs. cache-level in-flight deduplication so readers understand multiple
components will each have timers but won't cause duplicate concurrent network
fetches.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0647e542-9e75-4aca-b819-6f02d0d47b12

📥 Commits

Reviewing files that changed from the base of the PR and between 1047cdc and 32df0e7.

📒 Files selected for processing (3)
  • docs/config.json
  • docs/framework/react/guides/important-defaults.md
  • docs/framework/react/guides/polling.md

Copy link
Copy Markdown
Collaborator

@TkDodo TkDodo left a comment

Choose a reason for hiding this comment

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

thank you. I’m generally for adding this page, but left some feedback 🙏


[//]: # 'Example1'

Polling is independent of `staleTime`. A query can be fresh and still poll on schedule — `staleTime` controls when background refetches triggered by *mounting* or *window focus* happen. `refetchInterval` fires on its own clock regardless.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i wouldn’t mention mounting or window focus explicitly here. The list is not exhaustive and it might change over time, so I’d rather we link this to the important-defaults.md file where the triggers are explained.


## Polling with offline support

By default, queries skip fetches when the browser reports no network connection. If your app runs in environments where `navigator.onLine` is unreliable — embedded browsers, Electron, some WebViews — set `networkMode: 'always'` to ignore the online check:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we don’t use navigator.onLine anymore to determine network status. We only subscribe to online / offline browser events.


## Note on deduplication

Each `QueryObserver` — each component using `useQuery` with `refetchInterval` — runs its own timer. Two components subscribed to the same key with `refetchInterval: 5000` each fire their timer every 5 seconds. What's deduplicated is concurrent in-flight fetches: if two timers fire at overlapping moments, React Query won't issue two parallel network requests for the same key. The second fetch is held until the first settles. In practice, two components on the same polling interval produce one request per cycle, but the timers are observer-level, not query-level.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The second fetch is held until the first settles

this reads as if we queue requests up and the second one fires after the first one, which isn’t true. I’d just remove this sentence, it doesn’t add anything valuable imo.


## Pausing polling

Set `enabled: false` to stop polling when conditions aren't met. Any running interval is cleared immediately, and it restarts when `enabled` becomes `true` again:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hmm, setting enabled: false doesn’t only stop polling. To stop polling, I’d return false from the refetchInterval function. You can close over state values like tokenAddress. The refetchInterval function will re-run when the component re-renders or when data changes, and it will resume polling if you stop returning false from it.


[//]: # 'Example3'

## Disabling window-focus refetching in non-browser UIs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don’t think example 4 and 5 should be here. We explain those concepts in the react-native docs page, which is the most common non-browser UI being used. It shows how to set up custom focus manager listeners. turning off window focus refetching and replacing it with a 60s interval is also not advice I would give.

If anything, please move this section to the end, keep it short and link to the react-native docs.

- Remove staleTime enumeration; link to Important Defaults instead
- Remove game/kiosk focus management examples (scope creep)
- Rewrite pausing polling to use refetchInterval function instead of enabled: false
- Fix offline support section: connectivity uses online/offline events, not navigator.onLine
- Fix deduplication note: remove queuing implication and em dash
- Add non-browser environments note pointing to React Native guide
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 30, 2026

View your CI Pipeline Execution ↗ for commit 0fc4ddf

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded <1s View ↗
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 23s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-30 16:32:12 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10330

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10330

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10330

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10330

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10330

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10330

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10330

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10330

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10330

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10330

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10330

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10330

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10330

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10330

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10330

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10330

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10330

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10330

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10330

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10330

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10330

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10330

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10330

commit: 0fc4ddf

Copy link
Copy Markdown
Contributor Author

@Zelys-DFKH Zelys-DFKH left a comment

Choose a reason for hiding this comment

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

Addressed all five points:

  • Replaced the staleTime enumeration with a link to Important Defaults
  • Removed the game/kiosk focus management examples entirely
  • Rewrote "Pausing polling" to use refetchInterval returning false instead of enabled: false
  • Fixed the offline section to describe online/offline events rather than navigator.onLine
  • Cleaned up the deduplication note and added a short non-browser environments pointer at the end

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants