From eb7d144b91adae31b9840cc84f5ec7c45f003662 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Thu, 16 Apr 2026 00:25:32 -0600 Subject: [PATCH] fix chat scroll behaviour --- web/app/ai-chat/page.js | 11 +++-------- web/app/chat/page.js | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/web/app/ai-chat/page.js b/web/app/ai-chat/page.js index fc879dbc..3b43abf5 100644 --- a/web/app/ai-chat/page.js +++ b/web/app/ai-chat/page.js @@ -111,14 +111,9 @@ function AiChatPage() { lastScrolledIdRef.current = lastMsg.id; const area = messagesAreaRef.current; if (!area) return; - const isOwn = lastMsg.senderId === user?.id; - if (isOwn) { - messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); - } else { - const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150; - if (nearBottom) messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); - } - }, [messages, user?.id]); + const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150; + if (nearBottom) messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); + }, [messages]); useEffect(() => { if (!botTyping) return; diff --git a/web/app/chat/page.js b/web/app/chat/page.js index 3e243e8f..8f42cb35 100644 --- a/web/app/chat/page.js +++ b/web/app/chat/page.js @@ -109,14 +109,9 @@ function ChatPage() { lastScrolledIdRef.current = lastMsg.id; const area = messagesAreaRef.current; if (!area) return; - const isOwn = lastMsg.senderId === user?.id; - if (isOwn) { - area.scrollTop = area.scrollHeight; - } else { - const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 80; - if (nearBottom) area.scrollTop = area.scrollHeight; - } - }, [messages, user?.id]); + const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150; + if (nearBottom) area.scrollTop = area.scrollHeight; + }, [messages]); const fetchMessages = useCallback(async (convId) => { if (!token || !convId) return;