fix(web): Fix auto-scroll issue in chat dashboard

This commit is contained in:
WangzJi 2025-06-30 10:42:32 +08:00
parent ef7b17f9ab
commit f97c15b7ed
No known key found for this signature in database
GPG Key ID: C237805F3F8E1CB6

View File

@ -98,12 +98,15 @@ const Completion = ({ messages, onSubmit, onFormatContent }: Props) => {
// Process message content - if onFormatContent is provided and this is a dashboard chat,
// we'll extract the thinking part from vis-thinking code blocks
const processMessageContent = (content: any) => {
const processMessageContent = useCallback(
(content: any) => {
if (isChartChat && onFormatContent && typeof content === 'string') {
return onFormatContent(content);
}
return content;
};
},
[isChartChat, onFormatContent],
);
const [messageApi, contextHolder] = message.useMessage();
@ -198,7 +201,7 @@ const Completion = ({ messages, onSubmit, onFormatContent }: Props) => {
useEffect(() => {
console.log('Completion updating prevMessageCountRef:', {
currentLength: showMessages.length,
prevCount: prevMessageCountRef.current
prevCount: prevMessageCountRef.current,
});
// Only update if this is the first time (count is 0)
@ -241,7 +244,7 @@ const Completion = ({ messages, onSubmit, onFormatContent }: Props) => {
showMessagesLength: showMessages.length,
userRecentlyScrolled,
isUserScrolling: isUserScrollingRef.current,
isAutoScrolling: isAutoScrollingRef.current
isAutoScrolling: isAutoScrollingRef.current,
});
// Always handle new messages first - this is the highest priority
@ -285,7 +288,7 @@ const Completion = ({ messages, onSubmit, onFormatContent }: Props) => {
currentHeight,
lastHeight: lastContentHeightRef.current,
heightDiff,
threshold: 12
threshold: 12,
});
// Only scroll if content height increased by at least ~0.5 lines (12px) for smoother experience
@ -314,7 +317,7 @@ const Completion = ({ messages, onSubmit, onFormatContent }: Props) => {
console.log('Completion streaming blocked:', {
userRecentlyScrolled,
isUserScrolling: isUserScrollingRef.current,
isAutoScrolling: isAutoScrollingRef.current
isAutoScrolling: isAutoScrollingRef.current,
});
}
}, [showMessages, scene]);