From 2c32659f6a7e6041cea6481b44076190a722a0da Mon Sep 17 00:00:00 2001 From: gahusb Date: Mon, 18 May 2026 07:58:04 +0900 Subject: [PATCH] fix(agent-office): useAgentManager reconnect via ref to satisfy lint Previously connect's onclose handler referenced connect itself before the useCallback declaration, triggering react-hooks/immutability. Hold the latest connect in a ref (updated in useEffect) and call through it on reconnect. Same runtime behavior, lint-clean. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/pages/agent-office/hooks/useAgentManager.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/agent-office/hooks/useAgentManager.js b/src/pages/agent-office/hooks/useAgentManager.js index 1bc4282..70b35ae 100644 --- a/src/pages/agent-office/hooks/useAgentManager.js +++ b/src/pages/agent-office/hooks/useAgentManager.js @@ -12,6 +12,7 @@ export function useAgentManager() { const wsRef = useRef(null); const reconnectRef = useRef(null); + const connectRef = useRef(null); const connect = useCallback(() => { const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; @@ -68,12 +69,16 @@ export function useAgentManager() { ws.onclose = () => { setConnected(false); - reconnectRef.current = setTimeout(connect, WS_RECONNECT_DELAY); + reconnectRef.current = setTimeout(() => connectRef.current?.(), WS_RECONNECT_DELAY); }; ws.onerror = () => ws.close(); }, []); + useEffect(() => { + connectRef.current = connect; + }, [connect]); + useEffect(() => { connect(); return () => {