From 7755277877d3f0443ea264c915c763717be49ce0 Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 18 Sep 2025 19:07:25 +0700 Subject: [PATCH] also fix inconcistent appearing of scroll to bottom button when changing project versus a fresh load --- src/components/Shakespeare/ChatPane.tsx | 32 +++++++++++-------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 794da091..2a7e5d93 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -236,16 +236,6 @@ export const ChatPane = forwardRef(({ } }, [addRecentlyUsedModel, isConfigured, providerModel, searchParams, setSearchParams, startGeneration]); - // Function to check if user is at the bottom of the scroll area - const checkScrollPosition = () => { - if (!scrollAreaRef.current) return; - - const container = scrollAreaRef.current; - const threshold = 100; // 100px threshold - const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold; - - setShowScrollToBottom(!isNearBottom && container.scrollHeight > container.clientHeight); - }; // Function to scroll to bottom const scrollToBottom = () => { @@ -254,20 +244,28 @@ export const ChatPane = forwardRef(({ } }; - // Add scroll event listener + // Simple scroll event listener useEffect(() => { const container = scrollAreaRef.current; if (!container) return; - container.addEventListener('scroll', checkScrollPosition); + const handleScroll = () => { + const threshold = 100; + const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold; + const hasScrollableContent = container.scrollHeight > container.clientHeight; - // Check initial position - checkScrollPosition(); + setShowScrollToBottom(!isNearBottom && hasScrollableContent); + }; + + container.addEventListener('scroll', handleScroll); + + // Check immediately + handleScroll(); return () => { - container.removeEventListener('scroll', checkScrollPosition); + container.removeEventListener('scroll', handleScroll); }; - }, []); + }, [messages]); // Re-run when messages change to ensure proper setup useEffect(() => { if (scrollAreaRef.current && (messages || streamingMessage)) { @@ -281,8 +279,6 @@ export const ChatPane = forwardRef(({ container.scrollTop = container.scrollHeight; } - // Update scroll button visibility - checkScrollPosition(); } }, [messages, streamingMessage, isLoading]);