From 5467c3e1e31d0b09572d8f4f846502ea2b49e3d5 Mon Sep 17 00:00:00 2001 From: Arnas Donauskas Date: Thu, 16 Apr 2026 22:11:57 +0300 Subject: [PATCH] fix(inbox): re-clicking active conversation no longer clears messages Selecting the already-active conversation called setMessages([]) but the fetch effect in MessageThread only re-runs when conversationId changes, so messages stayed empty until the user left the page and came back. Bail out of handleSelectConversation when the clicked conversation is already active. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/app/(dashboard)/inbox/page.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/(dashboard)/inbox/page.tsx b/src/app/(dashboard)/inbox/page.tsx index 6779558..376ad50 100644 --- a/src/app/(dashboard)/inbox/page.tsx +++ b/src/app/(dashboard)/inbox/page.tsx @@ -139,11 +139,19 @@ export default function InboxPage() { [] ); - const handleSelectConversation = useCallback((conv: Conversation) => { - setActiveConversation(conv); - setActiveContact(conv.contact ?? null); - setMessages([]); - }, []); + const handleSelectConversation = useCallback( + (conv: Conversation) => { + // Re-clicking the already-active conversation would clear the + // messages array, but the fetch effect in MessageThread only re-runs + // when conversationId changes — so messages would stay empty until + // the user navigated away and back. Bail out early instead. + if (activeConversation?.id === conv.id) return; + setActiveConversation(conv); + setActiveContact(conv.contact ?? null); + setMessages([]); + }, + [activeConversation?.id] + ); const handleMessagesLoaded = useCallback((loaded: Message[]) => { setMessages(loaded);