fix: Resolved the issue where previous chat history persists after starting a new conversation.#144
Merged
Prajwal-Microsoft merged 2 commits intodevfrom Apr 1, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the React Query + UI reset logic in App to ensure chat state is properly isolated between sessions and that “New Chat” reliably starts with an empty conversation.
Changes:
- Updates
sendMessageMutation.onSuccessto write the new message into the cache for the mutation’ssessionId(instead of whatevercurrentSessionIdhappens to be at success time). - Adjusts session creation success handling to avoid clearing session id / invalidating all chat queries in
createNewSessionMutation. - Implements a “hard reset” flow in
handleNewChat(cancel/remove['chat']queries, clear session id, reset messages), and forcesChatSidebarremount on session change via akey.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prajwal-Microsoft
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the chat session management logic in the
Appcomponent to ensure chat history is properly reset and isolated between sessions, and fixes issues with updating chat data in the UI. The changes focus on preventing stale chat data from persisting across new sessions and ensuring UI components are correctly refreshed.Chat session and message management improvements:
onSuccesshandler for thesendMessageMutationnow uses the correctsessionIdfrom the mutation variables to update the chat cache, preventing messages from being added to the wrong session.onSuccesshandler for thecreateNewSessionMutationno longer clears the current session ID or invalidates all chat queries, as this is now handled elsewhere for better consistency.UI and state reset enhancements:
handleNewChatfunction now performs a hard reset of all chat query state by cancelling and removing queries with the['chat']key, clears the current session ID, resets the UI to an empty conversation, and then creates a new session. This prevents stale chat history from appearing in new conversations.ChatSidebarcomponent is now given akeybased on thecurrentSessionId, ensuring React fully resets the sidebar when the session changes, which helps avoid UI inconsistencies when starting a new chat.## PurposeDoes this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid
Other Information