Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): add auto-scroll when new messages arrive in chat (#12885)

Hiep Le2d085a6e0a00
diff --git a/frontend/src/components/features/chat/chat-interface.tsx b/frontend/src/components/features/chat/chat-interface.tsx
index 7ff989eecb..2d19ed7840 100644
--- a/frontend/src/components/features/chat/chat-interface.tsx
+++ b/frontend/src/components/features/chat/chat-interface.tsx
@@ -209,6 +209,21 @@ export function ChatInterface() {
setFeedbackPolarity(polarity);
};
+ // Auto-scroll to bottom when new messages arrive
+ React.useEffect(() => {
+ if (autoScroll) {
+ scrollDomToBottom();
+ }
+ // Note: We intentionally exclude autoScroll from deps because we only want
+ // to scroll when message content changes, not when autoScroll state changes.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [
+ v1UiEvents.length,
+ v0Events.length,
+ optimisticUserMessage,
+ scrollDomToBottom,
+ ]);
+
// Create a ScrollProvider with the scroll hook values
const scrollProviderValue = {
scrollRef,