fix(chat): reset scroll state when switching conversations (#29984)

This commit is contained in:
lif 2025-12-23 09:45:47 +08:00 committed by GitHub
parent 5a4f6f171b
commit 04ad68de70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -222,11 +222,16 @@ const Chat: FC<ChatProps> = ({
return () => container.removeEventListener('scroll', setUserScrolled)
}, [])
// Reset user scroll state when a new chat starts (length <= 1)
// Reset user scroll state when conversation changes or a new chat starts
// Track the first message ID to detect conversation switches (fixes #29820)
const prevFirstMessageIdRef = useRef<string | undefined>(undefined)
useEffect(() => {
if (chatList.length <= 1)
const firstMessageId = chatList[0]?.id
// Reset when: new chat (length <= 1) OR conversation switched (first message ID changed)
if (chatList.length <= 1 || (firstMessageId && prevFirstMessageIdRef.current !== firstMessageId))
userScrolledRef.current = false
}, [chatList.length])
prevFirstMessageIdRef.current = firstMessageId
}, [chatList])
useEffect(() => {
if (!sidebarCollapseState)