relay-tools / react-relay-network-modern

Relay Modern Network Layer with middlewares — cache, auth, retry, batch, logger, SSR
MIT License
327 stars 62 forks source link

Window Focus Refetching #125

Open redbar0n opened 3 years ago

redbar0n commented 3 years ago

Mirroring issue 3312 from Relay since it is a discussion there whether or not this should be handled in the Network Layer. If so, then it would be great if it was possible here.

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.

According to React Query's and URQL's comparison pages then it seems like Relay Modern Network Layer doesn't support Window Focus Refetching. Since it is not listed as an availability for Relay through any 3rd party library like this.

Above quote is from the similar request for Apollo Client. It has details and example code on how SWR and React Query implement window focus refetching, with a code sandbox example showing it, too. That might help for inspiration and/or discussion on a potential concrete implementation.

With the caveat that the URQL comparison page seems to have overlooked this react-relay-network-modern library, as it is referencing the classic react-relay-network-layer.

Does Window Focus Refetching make sense for Relay Modern Network Layer? If so, is it already baked in (contrary to what the above comparisons)? If not, is it on the roadmap? If not, why not?

nodkz commented 3 years ago

I'm not using Relay now in our projects. So there is no reason for me to do this. BUT I'll be very happy to accept PR with such improvement.