From d27bfbf481d535ceb834b3841e3419254c22271a Mon Sep 17 00:00:00 2001 From: projectmoon Date: Tue, 30 Jul 2024 19:45:20 +0200 Subject: [PATCH] Do not set websocket to null if in error state. --- ui/components/ChatWindow.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 0c58b59..17fca46 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -25,6 +25,7 @@ const useSocket = ( url: string, setIsWSReady: (ready: boolean) => void, setError: (error: boolean) => void, + hasError: boolean ) => { const [ws, setWs] = useState(null); @@ -183,7 +184,9 @@ const useSocket = ( ws.onclose = () => { clearTimeout(timeoutId); - setWs(null); + if (!hasError) { + setWs(null); // forces websocket to reopen when needed. + } console.log('[DEBUG] closed'); }; @@ -274,6 +277,7 @@ const ChatWindow = ({ id }: { id?: string }) => { process.env.NEXT_PUBLIC_WS_URL!, setIsWSReady, setHasError, + hasError ); const [loading, setLoading] = useState(false);