From 22943972c21e607819df2487674d691f10532c13 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 28 Jan 2026 19:15:25 +0200 Subject: [PATCH] fix(frontend): prevent infinite retry loop when chat clone fails Add cloneError state to track clone failures and prevent the useEffect from continuously retrying when completeClone() fails. --- .../[search_space_id]/new-chat/[[...chat_id]]/page.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index f6f70f83b..1f9dd433d 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -143,6 +143,7 @@ export default function NewChatPage() { const queryClient = useQueryClient(); const [isInitializing, setIsInitializing] = useState(true); const [isCompletingClone, setIsCompletingClone] = useState(false); + const [cloneError, setCloneError] = useState(false); const [threadId, setThreadId] = useState(null); const [currentThread, setCurrentThread] = useState(null); const [messages, setMessages] = useState([]); @@ -333,7 +334,7 @@ export default function NewChatPage() { // Handle clone completion when thread has clone_pending flag useEffect(() => { - if (!currentThread?.clone_pending || isCompletingClone) return; + if (!currentThread?.clone_pending || isCompletingClone || cloneError) return; const completeClone = async () => { setIsCompletingClone(true); @@ -351,13 +352,14 @@ export default function NewChatPage() { } catch (error) { console.error("[NewChatPage] Failed to complete clone:", error); toast.error("Failed to copy chat content. Please try again."); + setCloneError(true); } finally { setIsCompletingClone(false); } }; completeClone(); - }, [currentThread?.clone_pending, currentThread?.id, isCompletingClone, initializeThread, queryClient]); + }, [currentThread?.clone_pending, currentThread?.id, isCompletingClone, cloneError, initializeThread, queryClient]); // Handle scroll to comment from URL query params (e.g., from inbox item click) const searchParams = useSearchParams();