Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus aware query polling #856

Merged
merged 5 commits into from
Nov 2, 2022
Merged

Focus aware query polling #856

merged 5 commits into from
Nov 2, 2022

Conversation

johnnyomair
Copy link
Collaborator

Apollo does not support pausing polling when the current browser tab is not in focus (see feature request). Therefore we add our own useFocusAwareQuery hook that wraps useQuery and pauses/resumes polling upon focus/blur.

Apollo does not support pausing polling when the current browser tab is not in focus (see [feature request](apollographql/apollo-feature-requests#247)). Therefore we add our own `useFocusAwareQuery` hook that wraps `useQuery` and pauses/resumes polling upon focus/blur.
@johnnyomair johnnyomair self-assigned this Oct 24, 2022
@nsams
Copy link
Member

nsams commented Oct 24, 2022

better would be to avoid wrapping the hook, as you can only wrap once - to get one feature - but not twice. Some HOC system that let's the user do comoposition is a possible solution - but overkill in this case. Some kind of additional hook is nice imho (downside: not so easy to use as yours)

possible alternative: comet-admin has it's own useQuery with all features we need.

chernylu
chernylu previously approved these changes Oct 24, 2022
@johnnyomair
Copy link
Collaborator Author

@nsams what would you say to a solution like this?

const { data, startPolling, stopPolling, refetch } = useQuery(...);

useFocusAwarePolling({ pollInterval: 10000, startPolling, stopPolling, refetch });

@nsams
Copy link
Member

nsams commented Oct 25, 2022

👍

(not so easy to use, but still preferable for the aforementioned reason)

Wrapping the hook is not desirable as the hook can only be wrapped once. We therefore move the focus aware polling into a separate `useFocusAwarePolling` hook.
@johnnyomair
Copy link
Collaborator Author

Done in ac42702. Also added docs on how to use.

CHANGELOG.md Outdated Show resolved Hide resolved
@nsams
Copy link
Member

nsams commented Oct 25, 2022

Also added docs on how to use.

did you forget to git add them?

@johnnyomair
Copy link
Collaborator Author

did you forget to git add them?

No, they're right here: bad684a.

@kaufmo kaufmo merged commit 707d456 into main Nov 2, 2022
@kaufmo kaufmo deleted the focus-aware-polling branch November 2, 2022 07:07
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 participants