fix(#3996): reopen per-session SSE on tab re-show (reopen-bug fix)
#3996 closes the gateway + per-session SSE on hidden tabs to free HTTP/1.1 connection-pool slots (#3992). But the per-session-stream visibility hook guarded its reopen on _sessionStreamSessionId, which stopSessionStream() nulls — so the per-session SSE closed on hide but never reopened on re-show (regressing live-stream reattach). Capture the id into a dedicated _sessionStreamHiddenSid before the close and reopen from it on visibility return. Gateway hook (sessions.js) was already correct (reopens unconditionally + re-guards internally).
This commit is contained in:
parent
202d6df310
commit
5fdfb70bce
1 changed files with 12 additions and 3 deletions
|
|
@ -4202,6 +4202,9 @@ function stopApprovalPolling() {
|
|||
let _sessionEventSource = null;
|
||||
let _sessionStreamSessionId = null;
|
||||
let _sessionStreamReconnectTimer = null;
|
||||
// Holds the session id across a hidden-tab close so the visibility handler can
|
||||
// reopen the per-session SSE on re-show (stopSessionStream nulls _sessionStreamSessionId).
|
||||
let _sessionStreamHiddenSid = null;
|
||||
|
||||
function startSessionStream(sid) {
|
||||
if (!sid) return;
|
||||
|
|
@ -4210,13 +4213,19 @@ function startSessionStream(sid) {
|
|||
if (_sessionStreamSessionId === sid && _sessionEventSource) return;
|
||||
stopSessionStream();
|
||||
_sessionStreamSessionId = sid;
|
||||
// Visibility hook (install once) — mirror ensureSessionEventsSSE() pattern
|
||||
// Visibility hook (install once) — mirror ensureSessionEventsSSE() pattern.
|
||||
// Capture the active session id into a dedicated var BEFORE closing, because
|
||||
// stopSessionStream() nulls _sessionStreamSessionId — so the reopen path can't
|
||||
// rely on it (that was the bug: the stream never reopened on tab re-show).
|
||||
if (typeof document !== 'undefined' && !document._hermesSessionStreamVisibilityHook) {
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.hidden) {
|
||||
_sessionStreamHiddenSid = _sessionStreamSessionId;
|
||||
stopSessionStream();
|
||||
} else if (_sessionStreamSessionId) {
|
||||
void startSessionStream(_sessionStreamSessionId);
|
||||
} else if (_sessionStreamHiddenSid) {
|
||||
const resumeSid = _sessionStreamHiddenSid;
|
||||
_sessionStreamHiddenSid = null;
|
||||
void startSessionStream(resumeSid);
|
||||
}
|
||||
});
|
||||
document._hermesSessionStreamVisibilityHook = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue