fix: auto-scroll to bottom when switching chats on agents page (#22397)

When switching between chats on the agents page, the scroll position was
preserved from the previous chat instead of resetting to show the most
recent messages.

## Problem
Clicking a different chat in the sidebar loaded the new chat's messages
but kept the scroll container at whatever position the user had scrolled
to in the previous chat. This meant users often landed in the middle of
a conversation instead of at the bottom where the latest messages are.

## Fix
Added a `useEffect` in `AgentDetail` that resets `scrollTop` to `0`
whenever `agentId` changes. The scroll container uses
`flex-col-reverse`, so `scrollTop = 0` corresponds to the bottom (most
recent messages).
This commit is contained in:
Kyle Carberry
2026-02-27 14:00:50 -05:00
committed by GitHub
parent 0cfa03718e
commit 7043e773cf
+11
View File
@@ -385,6 +385,17 @@ const AgentDetail: FC = () => {
outletContext?.requestArchiveAgent ?? noopRequestArchiveAgent;
const scrollContainerRef = useRef<HTMLDivElement | null>(null);
// When switching between chats, reset the scroll container to the
// bottom (scrollTop 0 in a flex-col-reverse container) so the user
// always sees the most recent messages instead of a stale scroll
// position from the previous chat.
useEffect(() => {
void agentId;
if (scrollContainerRef.current) {
scrollContainerRef.current.scrollTop = 0;
}
}, [agentId]);
const chatQuery = useQuery({
...chat(agentId ?? ""),
enabled: Boolean(agentId),