fix(frontend/builder): auto-scroll to bottom when AI responds in chat panel

This commit is contained in:
Zamil Majdy
2026-04-08 02:07:13 +07:00
parent ffa955044d
commit 109f28d9d1

View File

@@ -9,7 +9,7 @@ import {
StopCircle,
X,
} from "@phosphor-icons/react";
import { KeyboardEvent, useRef, useState } from "react";
import { KeyboardEvent, useEffect, useRef, useState } from "react";
import type { CustomNode } from "../FlowEditor/nodes/CustomNode/CustomNode";
import { GraphAction } from "./helpers";
import { useBuilderChatPanel } from "./useBuilderChatPanel";
@@ -38,6 +38,11 @@ export function BuilderChatPanel({ className, isGraphLoaded }: Props) {
const messagesEndRef = useRef<HTMLDivElement>(null);
const isStreaming = status === "streaming" || status === "submitted";
// Scroll to bottom whenever a new message lands (AI response or user send)
useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
}, [messages.length]);
function handleSend() {
const text = inputValue.trim();
if (!text || isStreaming) return;