Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

lif04ad68de7023
diff --git a/web/app/components/base/chat/chat/index.tsx b/web/app/components/base/chat/chat/index.tsx
index 19c7b0da521..9864dda6ae2 100644
--- a/web/app/components/base/chat/chat/index.tsx
+++ b/web/app/components/base/chat/chat/index.tsx
@@ -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)