From 82ff92b5604a037bdfaa454f9b61d462f9f83aa6 Mon Sep 17 00:00:00 2001 From: Vedant Mahajan Date: Mon, 11 May 2026 23:39:11 +0530 Subject: [PATCH] fix: fetch chat history when opening recent conversations sheet (#919) --- apps/web/components/chat/index.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/web/components/chat/index.tsx b/apps/web/components/chat/index.tsx index 8ef1d22c..305dec43 100644 --- a/apps/web/components/chat/index.tsx +++ b/apps/web/components/chat/index.tsx @@ -399,6 +399,12 @@ export function ChatSidebar({ } }, [selectedProject]) + useEffect(() => { + if (!isHistoryOpen) return + fetchThreads() + analytics.chatHistoryViewed?.() + }, [isHistoryOpen, fetchThreads]) + const loadThread = useCallback( async (id: string) => { try { @@ -441,12 +447,14 @@ export function ChatSidebar({ // Auto-restore thread from URL on mount (e.g. reload or direct link) const didAutoLoadRef = useRef(false) + const initialThreadIdRef = useRef(threadId) useEffect(() => { if (didAutoLoadRef.current) return - if (!threadId) return + const initialThreadId = initialThreadIdRef.current + if (!initialThreadId) return didAutoLoadRef.current = true - loadThread(threadId) - }, [threadId, loadThread]) + loadThread(initialThreadId) + }, [loadThread]) const deleteThread = useCallback( async (threadId: string) => { @@ -596,10 +604,7 @@ export function ChatSidebar({ open={isHistoryOpen} onOpenChange={(open) => { setIsHistoryOpen(open) - if (open) { - fetchThreads() - analytics.chatHistoryViewed?.() - } else { + if (!open) { setConfirmingDeleteId(null) } }}