From 45d85bd907eacb7277154c74d52cbc7d7d9e212a Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Wed, 3 Jun 2026 23:21:19 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A4=20fix:=20Reload=20Messages=20When?= =?UTF-8?q?=20Reopening=20a=20Chat=20from=20a=20Non-Chat=20Route=20(#13501?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit navigateToConvo now removes the target conversation's cached messages before fetching, so a freshly-mounted ChatView refetches them. clearMessagesCache leaves a left conversation cached as [], and the messages query's refetchOnMount: false treats that empty array as valid — so returning to the conversation from a route where ChatRoute was unmounted (e.g. /projects) left the chat stuck on an empty cache with no /api/messages request. --- client/src/hooks/Conversations/useNavigateToConvo.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/src/hooks/Conversations/useNavigateToConvo.tsx b/client/src/hooks/Conversations/useNavigateToConvo.tsx index c8e7aa0b05..390f5b77d7 100644 --- a/client/src/hooks/Conversations/useNavigateToConvo.tsx +++ b/client/src/hooks/Conversations/useNavigateToConvo.tsx @@ -119,6 +119,14 @@ const useNavigateToConvo = (index = 0) => { clearAllConversations(true); clearMessagesCache(queryClient, currentConvoId); if (convo.conversationId !== Constants.NEW_CONVO && convo.conversationId) { + /** + * Remove (not just invalidate) the target's messages so a freshly-mounted + * ChatView refetches them. A prior `clearMessagesCache` can leave this + * conversation cached as `[]`, which the messages query's `refetchOnMount: false` + * would treat as valid — leaving the chat stuck on an empty cache with no + * request when navigating in from a non-chat route (e.g. /projects). + */ + queryClient.removeQueries([QueryKeys.messages, convo.conversationId]); queryClient.invalidateQueries([QueryKeys.conversation, convo.conversationId]); fetchFreshData(convo); } else {