Fix status flicker during WebSocket reconnect loop
connect() was unconditionally calling setStatus('connecting', ...) at the
top of each attempt, which flickered over "Disconnected — retrying..."
every 3 seconds during the retry loop.
Fix: only show "Connecting..." on the very first attempt (everConnected
is false). Once a connection has been established, preserve the
"Disconnected — retrying..." state across all subsequent reconnect
cycles until onopen fires. Also reset everConnected on Save so pointing
at a new server correctly shows "Connecting..." from a clean slate.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,7 +56,12 @@ function connect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearReconnectTimer();
|
clearReconnectTimer();
|
||||||
setStatus('connecting', 'Connecting...');
|
// Only show "Connecting..." on the very first attempt.
|
||||||
|
// Once we've ever connected, we're in a reconnect loop — preserve
|
||||||
|
// "Disconnected — retrying..." until onopen fires so there's no flicker.
|
||||||
|
if (!everConnected) {
|
||||||
|
setStatus('connecting', 'Connecting...');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ws = new WebSocket(getWsUrl());
|
ws = new WebSocket(getWsUrl());
|
||||||
@@ -249,7 +254,8 @@ async function init() {
|
|||||||
saveBtn.classList.remove('saved');
|
saveBtn.classList.remove('saved');
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
// Reconnect with new settings
|
// Reconnect with new settings (treat as fresh connection)
|
||||||
|
everConnected = false;
|
||||||
connect();
|
connect();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to save config:', e);
|
console.error('Failed to save config:', e);
|
||||||
|
|||||||
Reference in New Issue
Block a user