Skip to content

fix: Resolved the issue where previous chat history persists after starting a new conversation.#144

Merged
Prajwal-Microsoft merged 2 commits intodevfrom
psl-bug37791
Apr 1, 2026
Merged

fix: Resolved the issue where previous chat history persists after starting a new conversation.#144
Prajwal-Microsoft merged 2 commits intodevfrom
psl-bug37791

Conversation

@Prekshith-Microsoft
Copy link
Copy Markdown
Contributor

@Prekshith-Microsoft Prekshith-Microsoft commented Mar 20, 2026

This pull request improves the chat session management logic in the App component 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:

  • The onSuccess handler for the sendMessageMutation now uses the correct sessionId from the mutation variables to update the chat cache, preventing messages from being added to the wrong session.
  • The onSuccess handler for the createNewSessionMutation no 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:

  • The handleNewChat function 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.
  • The ChatSidebar component is now given a key based on the currentSessionId, ensuring React fully resets the sidebar when the session changes, which helps avoid UI inconsistencies when starting a new chat.## Purpose
  • ...

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.onSuccess to write the new message into the cache for the mutation’s sessionId (instead of whatever currentSessionId happens 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 forces ChatSidebar remount on session change via a key.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/App/src/App.tsx Outdated
@Prajwal-Microsoft Prajwal-Microsoft merged commit 4233650 into dev Apr 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants