diff --git a/web/src/app/chat/Chat.tsx b/web/src/app/chat/Chat.tsx index 8192d2cffcbd..467150321770 100644 --- a/web/src/app/chat/Chat.tsx +++ b/web/src/app/chat/Chat.tsx @@ -78,6 +78,21 @@ export const Chat = ({ // session they are using useEffect(() => { textareaRef.current?.focus(); + + // only clear things if we're going from one chat session to another + if (chatSessionId !== null && existingChatSessionId !== chatSessionId) { + // de-select documents + clearSelectedDocuments(); + // reset all filters + filterManager.setSelectedDocumentSets([]); + filterManager.setSelectedSources([]); + filterManager.setSelectedTags([]); + filterManager.setTimeRange(null); + if (isStreaming) { + setIsCancelled(true); + } + } + setChatSessionId(existingChatSessionId); async function initialSessionFetch() { @@ -405,9 +420,13 @@ export const Chat = ({ setSelectedMessageForDocDisplay(finalMessage.message_id); } await nameChatSession(currChatSessionId, currMessage); - router.push(`/chat?chatId=${currChatSessionId}`, { - scroll: false, - }); + + // NOTE: don't switch pages if the user has navigated away from the chat + if (currChatSessionId === chatSessionId) { + router.push(`/chat?chatId=${currChatSessionId}`, { + scroll: false, + }); + } } if ( finalMessage?.context_docs && @@ -464,9 +483,9 @@ export const Chat = ({ {documentSidebarInitialWidth !== undefined ? ( <> -