diff --git a/web/src/app/chat/components/message-list-view.tsx b/web/src/app/chat/components/message-list-view.tsx index 29ca98a..b925835 100644 --- a/web/src/app/chat/components/message-list-view.tsx +++ b/web/src/app/chat/components/message-list-view.tsx @@ -4,13 +4,13 @@ import { LoadingOutlined } from "@ant-design/icons"; import { motion } from "framer-motion"; import { Download, Headphones } from "lucide-react"; -import { useCallback, useMemo, useState } from "react"; +import { useCallback, useMemo, useRef, useState } from "react"; import { LoadingAnimation } from "~/components/deer-flow/loading-animation"; import { Markdown } from "~/components/deer-flow/markdown"; import { RainbowText } from "~/components/deer-flow/rainbow-text"; import { RollingText } from "~/components/deer-flow/rolling-text"; -import { ScrollContainer } from "~/components/deer-flow/scroll-container"; +import { ScrollContainer, type ScrollContainerRef } from "~/components/deer-flow/scroll-container"; import { Tooltip } from "~/components/deer-flow/tooltip"; import { Button } from "~/components/ui/button"; import { @@ -43,6 +43,7 @@ export function MessageListView({ options?: { interruptFeedback?: string }, ) => void; }) { + const scrollContainerRef = useRef(null); const messageIds = useStore((state) => state.messageIds); const interruptMessage = useStore((state) => { if (messageIds.length >= 2) { @@ -72,11 +73,23 @@ export function MessageListView({ (state) => state.ongoingResearchId === state.openResearchId, ); + const handleToggleResearch = useCallback(() => { + // Fix the issue where auto-scrolling to the bottom + // occasionally fails when toggling research. + const timer = setTimeout(() => { + if (scrollContainerRef.current) { + scrollContainerRef.current.scrollToBottom(); + } + }, 500); + return () => { clearTimeout(timer); }; + }, []); + return (