Skip to content

Commit 0c95567

Browse files
committed
Optimize auto scroll logic
1 parent b6c32e3 commit 0c95567

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/components/ChatSection.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ const ChatSection = () => {
2626
const [isLoading, setIsLoading] = useState(false);
2727
const [isServerOnline, setIsServerOnline] = useState(true);
2828
const messagesEndRef = useRef<HTMLDivElement>(null);
29+
const isInitialLoad = useRef(true);
2930

3031
const scrollToBottom = () => {
3132
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
3233
};
3334

3435
useEffect(() => {
36+
if (isInitialLoad.current) {
37+
isInitialLoad.current = false;
38+
return;
39+
}
3540
scrollToBottom();
3641
}, [messages]);
3742

0 commit comments

Comments
 (0)