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

[@mantine/hooks] Fixed initial value of the online attribute returned by useNetwork() #5766

Merged
merged 2 commits into from Feb 16, 2024

Conversation

jalik
Copy link
Contributor

@jalik jalik commented Feb 14, 2024

Fix #5765

@rtivital
Copy link
Member

It is not a valid solution. It will produce a hydration mismatch if the hook value is used to render content in frameworks with ssr.

[@mantine/hooks] Set the online status for environments without `navigator.connection` in `useNetwork()`
@jalik
Copy link
Contributor Author

jalik commented Feb 14, 2024

@rtivital you are right, I changed the code so the initial value is set in the useEffect() callback, thus only executed on the client.
The problem with the current code is that the online value relies on the presence of navigator.connection, but on Firefox and many other browsers this is not available (https://caniuse.com/netinfo), resulting in not setting the online value, even when available.

@rtivital rtivital merged commit 61bf3c0 into mantinedev:master Feb 16, 2024
@rtivital
Copy link
Member

Thanks!

rtivital pushed a commit that referenced this pull request Feb 16, 2024
…ed by `useNetwork()` in Firefox (#5766)

* [@mantine/hooks] Fixed initial value of the `online` attribute returned by `useNetwork()`

* Update use-network.ts

[@mantine/hooks] Set the online status for environments without `navigator.connection` in `useNetwork()`
@jalik jalik deleted the patch-2 branch February 16, 2024 16:27
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.

Initial value of online returned by useNetwork() is always true (even when offline)
2 participants