Skip to content

Comments

fix: reorder chat history sidebar after new message in existing chat#2795

Merged
hayescode merged 1 commit intoChainlit:mainfrom
hztBUAA:fix/chat-history-reorder
Feb 24, 2026
Merged

fix: reorder chat history sidebar after new message in existing chat#2795
hayescode merged 1 commit intoChainlit:mainfrom
hztBUAA:fix/chat-history-reorder

Conversation

@hztBUAA
Copy link
Contributor

@hztBUAA hztBUAA commented Feb 20, 2026

Summary

Fixes #2763

When sending a new message in an existing (resumed) chat, the chat history sidebar doesn't reorder to move the active chat to the top. This happens because the first_interaction socket event only fires once per session — so when a user resumes a thread and sends a message, no thread list refresh is triggered.

Changes

  • Added a useEffect in ThreadHistory that tracks message count changes
  • When a new user_message is detected in the current thread, the thread's createdAt is updated to the current time
  • This triggers groupByDate to re-sort the thread list, moving the active conversation to the top

How it works

The fix watches messages.length and compares it to the previous count via a ref. When:

  1. The message count increases (new message added)
  2. There were already messages (not the initial load)
  3. The latest message is a user_message
  4. The current thread exists in the history list and is not already at the top

...the thread's createdAt timestamp is updated, which causes the existing groupByDate sorting (in the threadHistoryState atom effect) to reposition the thread to the top of the "Today" group.

Test plan

  • Open an existing chat from the sidebar history
  • Send a new message in that chat
  • Verify the chat moves to the top of the history list immediately
  • Create a new chat and send a message — verify it still appears at the top correctly
  • Verify that resuming a thread without sending a message does not cause unnecessary reordering

Summary by cubic

Fixes the chat history sidebar not moving the active thread to the top after sending a message in a resumed chat. The active conversation now reorders immediately.

  • Bug Fixes
    • Detect new user messages by tracking messages.length in ThreadHistory.
    • Update the active thread’s createdAt to now, triggering the existing groupByDate sort.
    • No reordering on initial load or when resuming without sending a message.

Written for commit a20b60d. Summary will update on new commits.

When sending a new message in an existing/resumed chat, the thread's
position in the sidebar history list was not updated. This happened
because the first_interaction event only fires once per session, so
subsequent messages never triggered a thread list refresh.

Track message count changes and update the active thread's createdAt
timestamp when a new user message is detected, which triggers
groupByDate to re-sort and move the thread to the top of the list.

Fixes Chainlit#2763
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working frontend Pertains to the frontend. labels Feb 20, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@hayescode hayescode added this pull request to the merge queue Feb 24, 2026
Merged via the queue into Chainlit:main with commit e5c0114 Feb 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend Pertains to the frontend. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Chat history does not reorder after new message in an existing chat

2 participants