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) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 07:58:04 +09:00
parent add2d8044c
commit 2c32659f6a

View File

@@ -12,6 +12,7 @@ export function useAgentManager() {
const wsRef = useRef(null); const wsRef = useRef(null);
const reconnectRef = useRef(null); const reconnectRef = useRef(null);
const connectRef = useRef(null);
const connect = useCallback(() => { const connect = useCallback(() => {
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
@@ -68,12 +69,16 @@ export function useAgentManager() {
ws.onclose = () => { ws.onclose = () => {
setConnected(false); setConnected(false);
reconnectRef.current = setTimeout(connect, WS_RECONNECT_DELAY); reconnectRef.current = setTimeout(() => connectRef.current?.(), WS_RECONNECT_DELAY);
}; };
ws.onerror = () => ws.close(); ws.onerror = () => ws.close();
}, []); }, []);
useEffect(() => {
connectRef.current = connect;
}, [connect]);
useEffect(() => { useEffect(() => {
connect(); connect();
return () => { return () => {