You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(onlineManager): always initialize with online: true (#5714)
* fix(onlineManager): always initialize with `online: true`
instead of relying on navigator.onLine, because that indicator is broken AF in chrome
https://bugs.chromium.org/p/chromium/issues/list?q=navigator.online
* docs: document subscribe methods
* docs
* test: fix types in tests
setting to undefined is now illegal, so we have to reset to `true`, which is the default now
* fix(tests): switch from mocking navigator.onLine to mocking onlineManager.isOnline
* fix: offline toggle in devtools
it should now be enough to set online to true / false, without firing the event, because we always set & respect that value. we don't override the event handler, so real online / offline events might interfere here
* chore: fix tests
with the implementation of onlineManager, where we default to `true`, we need an explicit `'offline'` event to get it to false; otherwise, switching back to true doesn't change the state, so subscribers are not informed
* chore: prettier write
* chore: fix eslint
* chore: delete an old, flaky test that doesn't test much
Copy file name to clipboardExpand all lines: docs/react/guides/migrating-to-v5.md
+8
Original file line number
Diff line number
Diff line change
@@ -276,6 +276,14 @@ There are some caveats to this change however, which you must be aware of:
276
276
277
277
The `visibilitychange` event is used exclusively now. This is possible because we only support browsers that support the `visibilitychange` event. This fixes a bunch of issues [as listed here](https://github.com/TanStack/query/pull/4805).
278
278
279
+
### Network status no longer relies on the `navigator.onLine` property
280
+
281
+
`navigator.onLine` doesn't work well in Chromium based browsers. There are [a lot of issues](https://bugs.chromium.org/p/chromium/issues/list?q=navigator.online) around false negatives, which lead to Queries being wrongfully marked as `offline`.
282
+
283
+
To circumvent this, we now always start with `online: true` and only listen to `online` and `offline` events to update the status.
284
+
285
+
This should reduce the likelihood of false negatives, however, it might mean false positives for offline apps that load via serviceWorkers, which can work even without an internet connection.
286
+
279
287
### Removed custom `context` prop in favor of custom `queryClient` instance
280
288
281
289
In v4, we introduced the possibility to pass a custom `context` to all react-query hooks. This allowed for proper isolation when using MicroFrontends.
Copy file name to clipboardExpand all lines: docs/react/reference/onlineManager.md
+23-7
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,20 @@ id: OnlineManager
3
3
title: OnlineManager
4
4
---
5
5
6
-
The `OnlineManager` manages the online state within TanStack Query.
6
+
The `OnlineManager` manages the online state within TanStack Query. It can be used to change the default event listeners or to manually change the online state.
7
7
8
-
It can be used to change the default event listeners or to manually change the online state.
8
+
> Per default, the `onlineManager` assumes an active network connection, and listens to the `online` and `offline` events on the `window` object to detect changes.
9
+
10
+
> In previous versions, `navigator.onLine` was used to determine the network status. However, it doesn't work well in Chromium based browsers. There are [a lot of issues](https://bugs.chromium.org/p/chromium/issues/list?q=navigator.online) around false negatives, which lead to Queries being wrongfully marked as `offline`.
11
+
12
+
> To circumvent this, we now always start with `online: true` and only listen to `online` and `offline` events to update the status.
13
+
14
+
> This should reduce the likelihood of false negatives, however, it might mean false positives for offline apps that load via serviceWorkers, which can work even without an internet connection.
0 commit comments