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 {