fix: resolve merge conflicts with upstream main

This commit is contained in:
WangzJi 2025-06-30 10:28:27 +08:00
parent 235c336381
commit ef7b17f9ab
No known key found for this signature in database
GPG Key ID: C237805F3F8E1CB6
2 changed files with 41 additions and 45 deletions

View File

@ -39,7 +39,7 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
if (!scrollRef.current) return; if (!scrollRef.current) return;
const container = scrollRef.current; const container = scrollRef.current;
if (force) { if (force) {
// Force scroll for new messages - always scroll regardless of position // Force scroll for new messages - always scroll regardless of position
container.scrollTo({ container.scrollTo({
@ -86,9 +86,9 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
useEffect(() => { useEffect(() => {
console.log('ChatContentContainer updating prevMessageCountRef:', { console.log('ChatContentContainer updating prevMessageCountRef:', {
currentLength: history.length, currentLength: history.length,
prevCount: prevMessageCountRef.current prevCount: prevMessageCountRef.current,
}); });
// Only update if this is the first time (count is 0) // Only update if this is the first time (count is 0)
if (prevMessageCountRef.current === 0) { if (prevMessageCountRef.current === 0) {
prevMessageCountRef.current = history.length; prevMessageCountRef.current = history.length;
@ -101,9 +101,9 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
if (isAutoScrollingRef.current) { if (isAutoScrollingRef.current) {
return; return;
} }
lastScrollTimeRef.current = Date.now(); lastScrollTimeRef.current = Date.now();
if (scrollRef.current) { if (scrollRef.current) {
const scrollElement = scrollRef.current; const scrollElement = scrollRef.current;
const { scrollTop, scrollHeight, clientHeight } = scrollElement; const { scrollTop, scrollHeight, clientHeight } = scrollElement;
@ -120,7 +120,7 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
const isNewMessage = currentMessageCount > prevMessageCountRef.current; const isNewMessage = currentMessageCount > prevMessageCountRef.current;
const now = Date.now(); const now = Date.now();
const userRecentlyScrolled = now - lastScrollTimeRef.current < 2000; const userRecentlyScrolled = now - lastScrollTimeRef.current < 2000;
console.log('ChatContentContainer scroll check:', { console.log('ChatContentContainer scroll check:', {
currentMessageCount, currentMessageCount,
prevCount: prevMessageCountRef.current, prevCount: prevMessageCountRef.current,
@ -128,62 +128,62 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
historyLength: history.length, historyLength: history.length,
userRecentlyScrolled, userRecentlyScrolled,
isUserScrolling: isUserScrollingRef.current, isUserScrolling: isUserScrollingRef.current,
isAutoScrolling: isAutoScrollingRef.current isAutoScrolling: isAutoScrollingRef.current,
}); });
// Always handle new messages first - this is the highest priority // Always handle new messages first - this is the highest priority
if (isNewMessage) { if (isNewMessage) {
console.log('ChatContentContainer: New message detected, forcing scroll to bottom'); console.log('ChatContentContainer: New message detected, forcing scroll to bottom');
// New message - always scroll to bottom regardless of user position // New message - always scroll to bottom regardless of user position
isAutoScrollingRef.current = true; isAutoScrollingRef.current = true;
// Reset states IMMEDIATELY to ensure streaming can work // Reset states IMMEDIATELY to ensure streaming can work
lastScrollTimeRef.current = Date.now() - 3000; // Allow streaming immediately lastScrollTimeRef.current = Date.now() - 3000; // Allow streaming immediately
isUserScrollingRef.current = false; isUserScrollingRef.current = false;
lastContentHeightRef.current = scrollElement.scrollHeight; // Set current height as baseline lastContentHeightRef.current = scrollElement.scrollHeight; // Set current height as baseline
scrollElement.scrollTo({ scrollElement.scrollTo({
top: scrollElement.scrollHeight, top: scrollElement.scrollHeight,
behavior: 'smooth', behavior: 'smooth',
}); });
// Reset auto scroll flag after animation // Reset auto scroll flag after animation
setTimeout(() => { setTimeout(() => {
isAutoScrollingRef.current = false; isAutoScrollingRef.current = false;
}, 100); }, 100);
prevMessageCountRef.current = currentMessageCount; // Update count immediately prevMessageCountRef.current = currentMessageCount; // Update count immediately
return; // Exit early for new messages return; // Exit early for new messages
} }
// Handle streaming content updates (only if user hasn't manually scrolled recently) // Handle streaming content updates (only if user hasn't manually scrolled recently)
if (!userRecentlyScrolled && !isUserScrollingRef.current && !isAutoScrollingRef.current) { if (!userRecentlyScrolled && !isUserScrollingRef.current && !isAutoScrollingRef.current) {
// Streaming content - scroll based on content height change // Streaming content - scroll based on content height change
const currentHeight = scrollElement.scrollHeight; const currentHeight = scrollElement.scrollHeight;
// Initialize lastContentHeightRef if not set // Initialize lastContentHeightRef if not set
if (lastContentHeightRef.current === 0) { if (lastContentHeightRef.current === 0) {
lastContentHeightRef.current = currentHeight; lastContentHeightRef.current = currentHeight;
} }
const heightDiff = currentHeight - lastContentHeightRef.current; const heightDiff = currentHeight - lastContentHeightRef.current;
console.log('ChatContentContainer streaming check:', { console.log('ChatContentContainer streaming check:', {
currentHeight, currentHeight,
lastHeight: lastContentHeightRef.current, lastHeight: lastContentHeightRef.current,
heightDiff, heightDiff,
threshold: 12 threshold: 12,
}); });
// Only scroll if content height increased by at least ~0.5 lines (12px) for smoother experience // Only scroll if content height increased by at least ~0.5 lines (12px) for smoother experience
if (heightDiff >= 12) { if (heightDiff >= 12) {
// Clear any pending scroll timeout // Clear any pending scroll timeout
if (scrollTimeoutRef.current) { if (scrollTimeoutRef.current) {
clearTimeout(scrollTimeoutRef.current); clearTimeout(scrollTimeoutRef.current);
} }
console.log('ChatContentContainer: Triggering streaming scroll, heightDiff:', heightDiff); console.log('ChatContentContainer: Triggering streaming scroll, heightDiff:', heightDiff);
// Debounce scroll calls to avoid conflicts // Debounce scroll calls to avoid conflicts
scrollTimeoutRef.current = setTimeout(() => { scrollTimeoutRef.current = setTimeout(() => {
isAutoScrollingRef.current = true; isAutoScrollingRef.current = true;
@ -201,7 +201,7 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
console.log('ChatContentContainer streaming blocked:', { console.log('ChatContentContainer streaming blocked:', {
userRecentlyScrolled, userRecentlyScrolled,
isUserScrolling: isUserScrollingRef.current, isUserScrolling: isUserScrollingRef.current,
isAutoScrolling: isAutoScrollingRef.current isAutoScrolling: isAutoScrollingRef.current,
}); });
} }
}, [history]); }, [history]);
@ -229,7 +229,7 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
// Record user scroll time // Record user scroll time
lastScrollTimeRef.current = Date.now(); lastScrollTimeRef.current = Date.now();
// Determine if user is actively scrolling up // Determine if user is actively scrolling up
const atBottom = scrollTop + clientHeight >= scrollHeight - buffer; const atBottom = scrollTop + clientHeight >= scrollHeight - buffer;
isUserScrollingRef.current = !atBottom; isUserScrollingRef.current = !atBottom;
@ -276,11 +276,7 @@ const ChatContentContainer = ({}, ref: React.ForwardedRef<any>) => {
return ( return (
<div className='flex flex-1 relative'> <div className='flex flex-1 relative'>
<div <div ref={scrollRef} className='h-full w-full mx-auto overflow-y-auto' style={{ scrollBehavior: 'smooth' }}>
ref={scrollRef}
className='h-full w-full mx-auto overflow-y-auto'
style={{ scrollBehavior: 'smooth' }}
>
<ChatHeader isScrollToTop={isScrollToTop} /> <ChatHeader isScrollToTop={isScrollToTop} />
<ChatCompletion /> <ChatCompletion />
</div> </div>

View File

@ -100,9 +100,9 @@ const ChatCompletion: React.FC = () => {
useEffect(() => { useEffect(() => {
console.log('ChatCompletion updating prevMessageCountRef:', { console.log('ChatCompletion updating prevMessageCountRef:', {
currentLength: history.length, currentLength: history.length,
prevCount: prevMessageCountRef.current prevCount: prevMessageCountRef.current,
}); });
// Only update if this is the first time (count is 0) // Only update if this is the first time (count is 0)
if (prevMessageCountRef.current === 0) { if (prevMessageCountRef.current === 0) {
prevMessageCountRef.current = history.length; prevMessageCountRef.current = history.length;
@ -115,9 +115,9 @@ const ChatCompletion: React.FC = () => {
if (isAutoScrollingRef.current) { if (isAutoScrollingRef.current) {
return; return;
} }
lastScrollTimeRef.current = Date.now(); lastScrollTimeRef.current = Date.now();
if (scrollRef.current) { if (scrollRef.current) {
const scrollElement = scrollRef.current; const scrollElement = scrollRef.current;
const { scrollTop, scrollHeight, clientHeight } = scrollElement; const { scrollTop, scrollHeight, clientHeight } = scrollElement;
@ -142,7 +142,7 @@ const ChatCompletion: React.FC = () => {
historyLength: history.length, historyLength: history.length,
userRecentlyScrolled, userRecentlyScrolled,
isUserScrolling: isUserScrollingRef.current, isUserScrolling: isUserScrollingRef.current,
isAutoScrolling: isAutoScrollingRef.current isAutoScrolling: isAutoScrollingRef.current,
}); });
// Always handle new messages first - this is the highest priority // Always handle new messages first - this is the highest priority
@ -150,54 +150,54 @@ const ChatCompletion: React.FC = () => {
console.log('ChatCompletion: New message detected, forcing scroll to bottom'); console.log('ChatCompletion: New message detected, forcing scroll to bottom');
// New message - always scroll to bottom regardless of user position // New message - always scroll to bottom regardless of user position
isAutoScrollingRef.current = true; isAutoScrollingRef.current = true;
// Reset states IMMEDIATELY to ensure streaming can work // Reset states IMMEDIATELY to ensure streaming can work
lastScrollTimeRef.current = Date.now() - 3000; // Allow streaming immediately lastScrollTimeRef.current = Date.now() - 3000; // Allow streaming immediately
isUserScrollingRef.current = false; isUserScrollingRef.current = false;
lastContentHeightRef.current = scrollElement.scrollHeight; // Set current height as baseline lastContentHeightRef.current = scrollElement.scrollHeight; // Set current height as baseline
scrollElement.scrollTo({ scrollElement.scrollTo({
top: scrollElement.scrollHeight, top: scrollElement.scrollHeight,
behavior: 'smooth', behavior: 'smooth',
}); });
// Reset auto scroll flag after animation // Reset auto scroll flag after animation
setTimeout(() => { setTimeout(() => {
isAutoScrollingRef.current = false; isAutoScrollingRef.current = false;
}, 100); }, 100);
prevMessageCountRef.current = currentMessageCount; // Update count immediately prevMessageCountRef.current = currentMessageCount; // Update count immediately
return; // Exit early for new messages return; // Exit early for new messages
} }
// Handle streaming content updates (only if user hasn't manually scrolled recently) // Handle streaming content updates (only if user hasn't manually scrolled recently)
if (!userRecentlyScrolled && !isUserScrollingRef.current && !isAutoScrollingRef.current) { if (!userRecentlyScrolled && !isUserScrollingRef.current && !isAutoScrollingRef.current) {
// Streaming content - scroll based on content height change // Streaming content - scroll based on content height change
const currentHeight = scrollElement.scrollHeight; const currentHeight = scrollElement.scrollHeight;
// Initialize lastContentHeightRef if not set // Initialize lastContentHeightRef if not set
if (lastContentHeightRef.current === 0) { if (lastContentHeightRef.current === 0) {
lastContentHeightRef.current = currentHeight; lastContentHeightRef.current = currentHeight;
} }
const heightDiff = currentHeight - lastContentHeightRef.current; const heightDiff = currentHeight - lastContentHeightRef.current;
console.log('ChatCompletion streaming check:', { console.log('ChatCompletion streaming check:', {
currentHeight, currentHeight,
lastHeight: lastContentHeightRef.current, lastHeight: lastContentHeightRef.current,
heightDiff, heightDiff,
threshold: 12 threshold: 12,
}); });
// Only scroll if content height increased by at least ~0.5 lines (12px) for smoother experience // Only scroll if content height increased by at least ~0.5 lines (12px) for smoother experience
if (heightDiff >= 12) { if (heightDiff >= 12) {
// Clear any pending scroll timeout // Clear any pending scroll timeout
if (scrollTimeoutRef.current) { if (scrollTimeoutRef.current) {
clearTimeout(scrollTimeoutRef.current); clearTimeout(scrollTimeoutRef.current);
} }
console.log('ChatCompletion: Triggering streaming scroll, heightDiff:', heightDiff); console.log('ChatCompletion: Triggering streaming scroll, heightDiff:', heightDiff);
// Debounce scroll calls to avoid conflicts // Debounce scroll calls to avoid conflicts
scrollTimeoutRef.current = setTimeout(() => { scrollTimeoutRef.current = setTimeout(() => {
isAutoScrollingRef.current = true; isAutoScrollingRef.current = true;
@ -215,7 +215,7 @@ const ChatCompletion: React.FC = () => {
console.log('ChatCompletion streaming blocked:', { console.log('ChatCompletion streaming blocked:', {
userRecentlyScrolled, userRecentlyScrolled,
isUserScrolling: isUserScrollingRef.current, isUserScrolling: isUserScrollingRef.current,
isAutoScrolling: isAutoScrollingRef.current isAutoScrolling: isAutoScrollingRef.current,
}); });
} }
}, [history]); }, [history]);