fix(web): treat server clean close as session end without reconnect

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-03 16:07:46 +08:00
co-authored by Claude
parent 60524bad0e
commit 11ac0299a6
+14 -2
View File
@@ -111,6 +111,7 @@ export function useProcessWebSocket(
const reconnectTimeoutRef = useRef<number | null>(null);
const intentionalCloseRef = useRef(false);
const lastFrameWasExitRef = useRef(false);
const serverCleanCloseRef = useRef(false);
const callbacksRef = useRef(new Set<(data: string) => void>());
const clearReconnectTimeout = useCallback(() => {
@@ -157,6 +158,7 @@ export function useProcessWebSocket(
ws.onopen = () => {
reconnectAttemptsRef.current = 0;
lastFrameWasExitRef.current = false;
serverCleanCloseRef.current = false;
setStatus("open");
};
@@ -171,9 +173,19 @@ export function useProcessWebSocket(
callbacksRef.current.forEach((cb) => cb(data));
};
ws.onclose = () => {
ws.onclose = (event) => {
socketRef.current = null;
if (intentionalCloseRef.current || lastFrameWasExitRef.current) {
if (
(event.code === 1000 || event.code === 1001) &&
!intentionalCloseRef.current
) {
serverCleanCloseRef.current = true;
}
if (
intentionalCloseRef.current ||
lastFrameWasExitRef.current ||
serverCleanCloseRef.current
) {
setStatus("closed");
return;
}