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:
Agent
2026-03-12 01:19:51 +00:00
parent 9af3805f87
commit 9d12667de3

View File

@@ -56,7 +56,12 @@ function connect() {
}
clearReconnectTimer();
// 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 {
ws = new WebSocket(getWsUrl());
@@ -249,7 +254,8 @@ async function init() {
saveBtn.classList.remove('saved');
}, 1500);
// Reconnect with new settings
// Reconnect with new settings (treat as fresh connection)
everConnected = false;
connect();
} catch (e) {
console.error('Failed to save config:', e);