From 06ef615e596ab7cc83c5c017cf79ab9f985e259f Mon Sep 17 00:00:00 2001 From: Shanmuga Krishnan S M Date: Thu, 6 Aug 2026 14:39:09 +0530 Subject: [PATCH] fix(chatbot): stop browser window from auto-scrolling to bottom on mount --- src/pages/AIAssistant/AIAssistant.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/AIAssistant/AIAssistant.tsx b/src/pages/AIAssistant/AIAssistant.tsx index 855f775..03be91e 100644 --- a/src/pages/AIAssistant/AIAssistant.tsx +++ b/src/pages/AIAssistant/AIAssistant.tsx @@ -25,10 +25,18 @@ export default function AIAssistant() { const [input, setInput] = useState(''); const [isTyping, setIsTyping] = useState(false); const messagesEndRef = useRef(null); + const chatContainerRef = useRef(null); const inputRef = useRef(null); + const isInitialMount = useRef(true); useEffect(() => { - messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); + if (isInitialMount.current) { + isInitialMount.current = false; + return; + } + if (chatContainerRef.current) { + chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight; + } }, [messages, isTyping]); const sendMessage = async (text: string) => { @@ -178,6 +186,7 @@ export default function AIAssistant() { {/* Chat Container */}