fix thread scrolling

This commit is contained in:
Dinh Long Nguyen 2025-10-09 04:41:18 +07:00
parent fc784620e0
commit a2fbce698f

View File

@ -54,6 +54,7 @@ export const useThreadScrolling = (
} }
}, [scrollContainerRef]) }, [scrollContainerRef])
const handleScroll = useCallback((e: Event) => { const handleScroll = useCallback((e: Event) => {
const target = e.target as HTMLDivElement const target = e.target as HTMLDivElement
const { scrollTop, scrollHeight, clientHeight } = target const { scrollTop, scrollHeight, clientHeight } = target
@ -68,7 +69,7 @@ export const useThreadScrolling = (
setIsAtBottom(isBottom) setIsAtBottom(isBottom)
setHasScrollbar(hasScroll) setHasScrollbar(hasScroll)
lastScrollTopRef.current = scrollTop lastScrollTopRef.current = scrollTop
}, [streamingContent, setIsAtBottom, setHasScrollbar]) }, [streamingContent])
useEffect(() => { useEffect(() => {
const scrollContainer = scrollContainerRef.current const scrollContainer = scrollContainerRef.current
@ -77,7 +78,7 @@ export const useThreadScrolling = (
return () => return () =>
scrollContainer.removeEventListener('scroll', handleScroll) scrollContainer.removeEventListener('scroll', handleScroll)
} }
}, [handleScroll, scrollContainerRef]) }, [handleScroll])
const checkScrollState = useCallback(() => { const checkScrollState = useCallback(() => {
const scrollContainer = scrollContainerRef.current const scrollContainer = scrollContainerRef.current
@ -89,7 +90,7 @@ export const useThreadScrolling = (
setIsAtBottom(isBottom) setIsAtBottom(isBottom)
setHasScrollbar(hasScroll) setHasScrollbar(hasScroll)
}, [scrollContainerRef, setIsAtBottom, setHasScrollbar]) }, [])
useEffect(() => { useEffect(() => {
if (!scrollContainerRef.current) return if (!scrollContainerRef.current) return
@ -100,7 +101,7 @@ export const useThreadScrolling = (
scrollToBottom(false) scrollToBottom(false)
checkScrollState() checkScrollState()
} }
}, [checkScrollState, scrollToBottom, scrollContainerRef]) }, [checkScrollState, scrollToBottom])
const prevCountRef = useRef(messageCount) const prevCountRef = useRef(messageCount)
@ -145,7 +146,7 @@ export const useThreadScrolling = (
} }
prevCountRef.current = messageCount prevCountRef.current = messageCount
}, [messageCount, lastMessageRole, getDOMElements, setPaddingHeight]) }, [messageCount, lastMessageRole])
useEffect(() => { useEffect(() => {
const previouslyStreaming = wasStreamingRef.current const previouslyStreaming = wasStreamingRef.current
@ -196,7 +197,7 @@ export const useThreadScrolling = (
} }
wasStreamingRef.current = currentlyStreaming wasStreamingRef.current = currentlyStreaming
}, [streamingContent, threadId, getDOMElements, setPaddingHeight]) }, [streamingContent, threadId])
useEffect(() => { useEffect(() => {
userIntendedPositionRef.current = null userIntendedPositionRef.current = null
@ -206,7 +207,7 @@ export const useThreadScrolling = (
prevCountRef.current = messageCount prevCountRef.current = messageCount
scrollToBottom(false) scrollToBottom(false)
checkScrollState() checkScrollState()
}, [threadId, messageCount, scrollToBottom, checkScrollState, setPaddingHeight]) }, [threadId])
return useMemo( return useMemo(
() => ({ () => ({