fix(web): dismiss stale connection error toast after ws reconnect (#1474)

This commit is contained in:
qer 2026-07-07 20:47:56 +08:00 committed by GitHub
parent 2065ae4615
commit 11c6a37ce0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---
web: Fix the connection error toast lingering after the WebSocket reconnects when returning from the background.

View file

@ -929,6 +929,12 @@ function connectEventsIfNeeded(): void {
onConnectionChange(connected: boolean) {
rawState.connected = connected;
rawState.connection = connected ? 'connected' : 'disconnected';
// The data channel is healthy again (server_hello received). Clear any
// stale "Realtime connection error" toast instead of relying on its
// auto-dismiss timer: iOS Safari freezes timers while a tab is
// backgrounded, so the toast would otherwise linger until a manual
// refresh even though the reconnect already succeeded.
if (connected) dismissWsError();
},
});
}
@ -1095,6 +1101,19 @@ function pushWarning(warning: AppWarning): void {
rawState.warnings = [...rawState.warnings, warning];
}
// Drop every "Realtime connection error" notice pushed by the WS onError
// handler. Matched by severity + the localized wsTitle (the same i18n instance
// used to push it), so other errors are left untouched.
function dismissWsError(): void {
const title = i18n.global.t('warnings.wsTitle');
const next = rawState.warnings.filter(
(w) => !(typeof w === 'object' && w !== null && w.severity === 'error' && w.title === title),
);
if (next.length !== rawState.warnings.length) {
rawState.warnings = next;
}
}
function pushOperationFailure(
operation: string,
err: unknown,