From 5700a2d3c3dc409a8bde3cfa971beeb9b897435f Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Sat, 07 Mar 2026 12:09:43 +0100
Subject: [PATCH] fix: instant scroll on session switch, scroll on transcript reflection

---
 components/chat/MessageList.tsx |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/components/chat/MessageList.tsx b/components/chat/MessageList.tsx
index 0076e5c..6ec43bb 100644
--- a/components/chat/MessageList.tsx
+++ b/components/chat/MessageList.tsx
@@ -13,14 +13,23 @@
 
 export function MessageList({ messages, isTyping, onDeleteMessage }: MessageListProps) {
   const listRef = useRef<FlatList<Message>>(null);
+  const prevLengthRef = useRef(0);
+
+  // Track the last message's content so transcript reflections trigger a scroll
+  const lastContent = messages.length > 0 ? messages[messages.length - 1].content : "";
 
   useEffect(() => {
     if (messages.length > 0) {
+      // If the message count changed by more than 1, it's a session switch —
+      // snap to bottom instantly instead of visibly scrolling down.
+      const delta = Math.abs(messages.length - prevLengthRef.current);
+      const animated = delta === 1;
       setTimeout(() => {
-        listRef.current?.scrollToEnd({ animated: true });
+        listRef.current?.scrollToEnd({ animated });
       }, 50);
     }
-  }, [messages.length, isTyping]);
+    prevLengthRef.current = messages.length;
+  }, [messages.length, isTyping, lastContent]);
 
   // Play from a voice message and auto-chain all consecutive assistant voice messages after it
   const handlePlayVoice = useCallback(async (messageId: string) => {
@@ -61,9 +70,6 @@
         />
       )}
       contentContainerStyle={{ paddingVertical: 12 }}
-      onContentSizeChange={() => {
-        listRef.current?.scrollToEnd({ animated: false });
-      }}
       showsVerticalScrollIndicator={false}
       ListFooterComponent={
         <>

--
Gitblit v1.3.1