From 56d1ffa136443a69e7a11ebdb4701ac71775c7b6 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 23 Dec 2024 18:55:51 +0800 Subject: [PATCH] fix: scroll bottom when generation text (#4323) * fix: scroll bottom when generation text * chore: update logic when prepare generate * chore: fix case no switch thread * chore: remore dep thread id * chore: handle fix generation without have dep thread id --- .../ThreadCenterPanel/ChatBody/index.tsx | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx index 29595f2491..f384611c5e 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx @@ -85,24 +85,33 @@ const ChatBody = memo( overscan: 5, }) + useEffect(() => { + if (parentRef.current) { + parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) + virtualizer.scrollToIndex(count - 1) + } + }, [count, virtualizer]) + useEffect(() => { if (parentRef.current && isGeneratingResponse) { - requestAnimationFrame(() => { - if (parentRef.current) { - parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) - } - }) + parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) + virtualizer.scrollToIndex(count - 1) } }, [count, virtualizer, isGeneratingResponse]) + useEffect(() => { + if (parentRef.current && isGeneratingResponse) { + parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) + virtualizer.scrollToIndex(count - 1) + } + }, [count, virtualizer, isGeneratingResponse, currentThread?.id]) + useEffect(() => { isUserManuallyScrollingUp.current = false - requestAnimationFrame(() => { - if (parentRef.current) { - parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) - virtualizer.scrollToIndex(count - 1) - } - }) + if (parentRef.current) { + parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) + virtualizer.scrollToIndex(count - 1) + } }, [count, currentThread?.id, virtualizer]) const items = virtualizer.getVirtualItems()