From 8c1f13378b8d02e7c3305778e603b92f10639c2a Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 23 Dec 2024 16:04:48 +0700 Subject: [PATCH 1/5] fix: scroll bottom when generation text --- .../ThreadCenterPanel/ChatBody/index.tsx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx index 29595f2491..9d7514123b 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx @@ -87,22 +87,16 @@ const ChatBody = memo( useEffect(() => { if (parentRef.current && isGeneratingResponse) { - requestAnimationFrame(() => { - if (parentRef.current) { - parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) - } - }) + parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) } - }, [count, virtualizer, isGeneratingResponse]) + }, [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() From b1571002b2e5d16d70759c9350666ff3d95ca426 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 23 Dec 2024 16:15:18 +0700 Subject: [PATCH 2/5] chore: update logic when prepare generate --- web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx index 9d7514123b..63a39eb2cc 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx @@ -88,6 +88,7 @@ const ChatBody = memo( useEffect(() => { if (parentRef.current && isGeneratingResponse) { parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) + virtualizer.scrollToIndex(count - 1) } }, [count, virtualizer, isGeneratingResponse, currentThread?.id]) From 600cedb766896901c8a542ce9684b476eaa4ef2a Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 23 Dec 2024 16:16:55 +0700 Subject: [PATCH 3/5] chore: fix case no switch thread --- web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx index 63a39eb2cc..a93d44cfb4 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx @@ -85,6 +85,13 @@ const ChatBody = memo( overscan: 5, }) + useEffect(() => { + if (parentRef.current) { + parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) + virtualizer.scrollToIndex(count - 1) + } + }, [count, virtualizer, currentThread?.id]) + useEffect(() => { if (parentRef.current && isGeneratingResponse) { parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) From 45e613592e5fc8811f40728b8bd4a342225c513d Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 23 Dec 2024 16:20:45 +0700 Subject: [PATCH 4/5] chore: remore dep thread id --- web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx index a93d44cfb4..0ae6896fdf 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx @@ -90,7 +90,7 @@ const ChatBody = memo( parentRef.current.scrollTo({ top: parentRef.current.scrollHeight }) virtualizer.scrollToIndex(count - 1) } - }, [count, virtualizer, currentThread?.id]) + }, [count, virtualizer]) useEffect(() => { if (parentRef.current && isGeneratingResponse) { From c4db8b9479bc7cd4541948e784349fab859ec3c0 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 23 Dec 2024 16:28:08 +0700 Subject: [PATCH 5/5] chore: handle fix generation without have dep thread id --- web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx index 0ae6896fdf..f384611c5e 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx @@ -92,6 +92,13 @@ const ChatBody = memo( } }, [count, virtualizer]) + useEffect(() => { + if (parentRef.current && isGeneratingResponse) { + 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 })