question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Window Focus Refetching

See original GitHub issue

From FR #247

Currently, Apollo Client’s pollInterval refetches every n milliseconds, regardless of whether the user is actively using the page or not, which isn’t optimized. Rising libraries such as SWR or React Query support focus refetching, meaning that the client will not poll if the user has switched to a different tab or window, and it will immediately fetch again if the user comes back to the tab. This saves a lot of wasted requests, while maintaining a great UX.

It would be nice to see such feature implemented in Apollo Client as well.

This is how these 2 libraries implement the focus:

~https://github.com/vercel/swr/search?q=isDocumentVisible&unscoped_q=isDocumentVisible~ ~https://github.com/tannerlinsley/react-query/search?q=isDocumentVisible&unscoped_q=isDocumentVisible~

See FR #247 for more details as it contains a lot of good commentary from the community.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:9
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
xcv58commented, Aug 1, 2022

Hi @jpvajda,

I build a proof of concept implementation: https://github.com/xcv58/apollo-client/pull/1/files#diff-ebf1072d16b9775e8cae2d74140e5da612378bf107621ab70c3769b3c4d31ee5

I think this implementation is not optimal since it will add listeners for each query with the refetchOnFocus: true option. We can add the global listeners on QueryManager class once and use its this.queries.forEach to broadcast when the focus state change and let individual QueryInfo handle the events.

Could you please take a look and share your feedback?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Window Focus Refetching | TanStack Query Docs
If a user leaves your application and returns to stale data, React Query automatically requests fresh data for you in the background.
Read more >
React Query - refetch on window focus but not otherwise?
refetchOnWindowFocus defaults to true , which will only refetch stale queries. Set it to always to, well, always refetch.
Read more >
Window Focus Refetching | Svelte Query | SvelteStack
Window Focus Refetching. If a user leaves your application and returns to stale data, Svelte Query automatically requests fresh data for you in...
Read more >
Real world usage: react-query Window Focus Refetching
In this article, I'll show you how to find out when users change tabs in browsers using JavaScript....
Read more >
Adyasha on Twitter: "Benefits of React Query: - Twitter
Benefits of React Query: - Window focus refetching – When a user leaves your tab, React Query marks the data “stale” and refetches...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found