Improve accuracy in determining visibility state#4120
Open
dcondrey wants to merge 6 commits intovercel:mainfrom
Open
Improve accuracy in determining visibility state#4120dcondrey wants to merge 6 commits intovercel:mainfrom
dcondrey wants to merge 6 commits intovercel:mainfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
shuding
reviewed
Nov 28, 2025
b2aadc1 to
4a2c832
Compare
Enhanced visibility check. Resolves vercel#3039
no longer using isUndefined
- Change isActive() to accept hasFocus() as alternative to isVisible(), fixing revalidateOnFocus in Chrome where visibilityState can be stale - Default refreshWhenUnfocused to falsy (consistent with refreshWhenHidden and refreshWhenOffline), so polling pauses on alt-tab via hasFocus() - Restore isActive() in FOCUS_EVENT handler (was incorrectly changed to isOnline() only) - Rewrite unit tests to verify actual behavior with mocked state - Update mockVisibilityHidden() to also mock hasFocus() for accuracy Fixes vercel#3039, vercel#4130
ba9a7db to
dea54ff
Compare
Add explicit type annotation to the `use` constant so TypeScript sees a single callable signature instead of trying to unify incompatible overloaded signatures from React.use and the inline fallback.
Author
|
Note: Added a fix for the failing test-typing CI checks. The use polyfill in src/index/use-swr.ts was defined as a union of React.use and an inline fallback whose signatures TypeScript 5.9 couldn't unify, causing TS2349: This expression is not callable errors. Added an explicit type annotation to give it a single callable signature. This is unrelated to the visibility/focus changes. |
promer94
previously approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Separated isVisible() and hasFocus() and poll conditions independently.
Related Issues
Fixes #3039, #4130