diff --git a/web/src/lib/api/process.ts b/web/src/lib/api/process.ts index 89713cc..1d1b50c 100644 --- a/web/src/lib/api/process.ts +++ b/web/src/lib/api/process.ts @@ -111,6 +111,7 @@ export function useProcessWebSocket( const reconnectTimeoutRef = useRef(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; }