Skip to content

Add focusThrottleInterval to throttle revalidations on focus - #117

Merged
MattCCC merged 3 commits into
masterfrom
focus-throttle
Sep 27, 2026
Merged

MattCCC merged 3 commits into
masterfrom
focus-throttle

Conversation

@MattCCC

@MattCCC MattCCC commented Sep 27, 2026

Copy link
Copy Markdown
Owner

This pull request adds focusThrottleInterval, which throttles the revalidations of refetchOnFocus, so that users switching between tabs quickly don't trigger a request every time.

✨ Features & Improvements

  • Added focusThrottleInterval: within this time (in milliseconds) after a request or its revalidation, the window regaining focus doesn't revalidate it again. It defaults to 5 seconds, like in SWR, and 0 revalidates on every focus. It can be set globally, per endpoint or per request.
  • It works with browser focus events and custom event providers registered with setEventProvider('focus', ...), e.g. in React Native.
  • Revalidations on reconnect and calls of revalidateAll('focus') aren't throttled.
  • Documented in the settings table and the Focus Revalidation section.

⚠️ Behavior Change

The window regaining focus within 5 seconds after a request or its revalidation no longer revalidates it. Set focusThrottleInterval: 0 to revalidate on every focus like before.

🧪 Tests

  • The default interval, a custom one, 0, and no throttling of revalidateAll() calls and revalidations on reconnect.
  • Existing tests that focus the window right after the first request now set focusThrottleInterval: 0.
  • Coverage stays at 100%.

📦 Bundle Size

The core bundles grow by less than 0.1 KB (brotli). The size limits are raised to fit this and the other pull requests opened alongside it, so that they can be merged in any order.


Generated by Claude Code

Within focusThrottleInterval milliseconds after a request or its revalidation, the window regaining focus doesn't revalidate it again, so that refetchOnFocus doesn't send a request every time users switch between tabs quickly. It defaults to 5 seconds, and 0 revalidates on every focus. Revalidations on reconnect and calls of revalidateAll() aren't throttled.
Core bundles 7.75 KB -> 8.75 KB, dist/react/index.mjs 10.75 KB -> 11.75 KB and dist/react/index.js 11.75 KB -> 12.75 KB. The limits fit this and the other PRs opened alongside it (abort signal fix, ETag revalidation, retry jitter and methods, onDownloadProgress, responseType, focusThrottleInterval, initialData and typed OpenAPI endpoints), which add about 1 KB together, so that they can be merged in any order.
@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
dist/browser/index.mjs 7.35 KB (+0.47% 🔺)
dist/browser/index.global.js 7.52 KB (+0.51% 🔺)
dist/node/index.js 7.43 KB (+0.55% 🔺)
dist/react/index.mjs 10.38 KB (+0.44% 🔺)
dist/react/index.js 11.26 KB (+0.41% 🔺)

@MattCCC
MattCCC merged commit 9618a4f into master Sep 27, 2026
14 checks passed
@MattCCC
MattCCC deleted the focus-throttle branch September 27, 2026 20:19
@MattCCC MattCCC mentioned this pull request Sep 27, 2026
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.

2 participants