fix(realtime): open no socket after a logout, and reconnect as soon as the network is back

A connect still waiting for its ws token when the user logged out went on
to open a socket authenticated as that user, which the next login on the
same browser then reused. And a socket in its reconnect backoff waited up
to 30 s after the network came back or the tab became visible. Both
events now reconnect right away.
This commit is contained in:
Maurice
2026-10-07 16:25:00 +02:00
parent f02253a44c
commit 3f9b751ee3
5 changed files with 71 additions and 4 deletions
+3 -1
View File
@@ -15,7 +15,7 @@
import { mutationQueue } from './mutationQueue'
import { tripSyncManager } from './tripSyncManager'
import { isEffectivelyOnline, onNetworkModeChange } from './networkMode'
import { setPreReconnectHook, setRefetchCallback, getActiveTrips } from '../api/websocket'
import { setPreReconnectHook, setRefetchCallback, getActiveTrips, reconnectNow } from '../api/websocket'
import { useTripStore } from '../store/tripStore'
import { useSettingsStore } from '../store/settingsStore'
import { useAuthStore } from '../store/authStore'
@@ -61,6 +61,7 @@ function onOnline() {
// routes through onNetworkMode → here with the force flag already cleared).
if (!isEffectivelyOnline()) return
ensureSettingsLoaded()
reconnectNow()
mutationQueue.flush()
.catch(console.error)
.finally(() => {
@@ -73,6 +74,7 @@ function onOnline() {
function onVisibility() {
if (!document.hidden && isEffectivelyOnline()) {
ensureSettingsLoaded()
reconnectNow()
mutationQueue.flush().catch(console.error)
}
}