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

Offline Detection? #35

Open
rrLucho opened this issue Nov 25, 2019 · 4 comments
Open

Offline Detection? #35

rrLucho opened this issue Nov 25, 2019 · 4 comments

Comments

@rrLucho
Copy link

rrLucho commented Nov 25, 2019

is there a way to detect offline state in the network, so we can serve different content, using the hooks?

@mlampedx
Copy link
Contributor

mlampedx commented Nov 27, 2019

I think this would be a great addition to the useNetworkStatus hook. I think the online/offline events API could be used.

@JCofman
Copy link

JCofman commented Jan 8, 2020

Hi :)

I created a pull request for this feature -> #45

@anton-karlovskiy
Copy link
Contributor

We shouldn't land support for navigator.onLine API because the API itself is unreliable.

https://natalian.org/2012/07/16/navigator.onLine/
https://blog.superhuman.com/building-reliable-apps-on-unreliable-networks-3f75743fc457

The way browsers implement navigator.onLine means that you would likely need to do something much more custom to get what you are actually after.

Per MDN, in Chrome and Safari, if the browser is not able to connect to a local area network (LAN) or a router, it is offline; all other conditions return true. So while you can assume that the browser is offline when it returns a false value, you cannot assume that a true value necessarily means that the browser can access the internet.

@JCofman
Copy link

JCofman commented Mar 17, 2020

As mentioned by @anton-karlovskiy the method used for the pull request is fragile but if you still want to use offline detection using the navigator.onLine API you can checkout -> https://github.com/jaredpalmer/the-platform#usenetworkstatus

I think we can close this issue? :)

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

No branches or pull requests

4 participants