From f7f696bf107266c3cbc4d1c5a7d1a5f3af7f1e14 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Tue, 24 Feb 2026 18:13:31 -0800 Subject: [PATCH] Remove rerender thrashing on setConnected --- frontend/src/useWebSocket.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/src/useWebSocket.ts b/frontend/src/useWebSocket.ts index 4e3bc61..98b1d66 100644 --- a/frontend/src/useWebSocket.ts +++ b/frontend/src/useWebSocket.ts @@ -1,4 +1,4 @@ -import { useEffect, useRef, useCallback, useState } from 'react'; +import { useEffect, useRef, useCallback } from 'react'; import type { HealthStatus, Contact, Message, MessagePath, RawPacket } from './types'; interface WebSocketMessage { @@ -30,7 +30,6 @@ export function useWebSocket(options: UseWebSocketOptions) { const wsRef = useRef(null); const reconnectTimeoutRef = useRef(null); const shouldReconnectRef = useRef(true); - const [connected, setConnected] = useState(false); // Store options in ref to avoid stale closures in WebSocket handlers. // The onmessage callback captures this ref, and we keep the ref updated @@ -58,7 +57,6 @@ export function useWebSocket(options: UseWebSocketOptions) { ws.onopen = () => { console.log('WebSocket connected'); - setConnected(true); if (reconnectTimeoutRef.current) { clearTimeout(reconnectTimeoutRef.current); reconnectTimeoutRef.current = null; @@ -67,7 +65,6 @@ export function useWebSocket(options: UseWebSocketOptions) { ws.onclose = () => { console.log('WebSocket disconnected'); - setConnected(false); wsRef.current = null; if (!shouldReconnectRef.current) { @@ -160,5 +157,4 @@ export function useWebSocket(options: UseWebSocketOptions) { }; }, [connect]); - return { connected }; }