diff --git a/lightrag_webui/src/features/RetrievalTesting.tsx b/lightrag_webui/src/features/RetrievalTesting.tsx index 97d41fe1..bde4414b 100644 --- a/lightrag_webui/src/features/RetrievalTesting.tsx +++ b/lightrag_webui/src/features/RetrievalTesting.tsx @@ -18,11 +18,28 @@ export default function RetrievalTesting() { const [inputValue, setInputValue] = useState('') const [isLoading, setIsLoading] = useState(false) const messagesEndRef = useRef(null) + const messagesContainerRef = useRef(null) - const scrollToBottom = useCallback(() => { - messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) + // Check if the container is near the bottom + const isNearBottom = useCallback(() => { + const container = messagesContainerRef.current + if (!container) return true // Default to true if no container reference + + // Calculate distance to bottom + const { scrollTop, scrollHeight, clientHeight } = container + const distanceToBottom = scrollHeight - scrollTop - clientHeight + + // Consider near bottom if less than 100px from bottom + return distanceToBottom < 100 }, []) + const scrollToBottom = useCallback((force = false) => { + // Only scroll if forced or user is already near bottom + if (force || isNearBottom()) { + messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) + } + }, [isNearBottom]) + const handleSubmit = useCallback( async (e: React.FormEvent) => { e.preventDefault() @@ -60,7 +77,8 @@ export default function RetrievalTesting() { } return newMessages }) - scrollToBottom() + // Don't force scroll when updating with new chunks + scrollToBottom(false) } // Prepare query parameters @@ -106,7 +124,7 @@ export default function RetrievalTesting() { ) const debouncedMessages = useDebounce(messages, 100) - useEffect(() => scrollToBottom(), [debouncedMessages, scrollToBottom]) + useEffect(() => scrollToBottom(false), [debouncedMessages, scrollToBottom]) const clearMessages = useCallback(() => { setMessages([]) @@ -117,7 +135,7 @@ export default function RetrievalTesting() {
-
+
{messages.length === 0 ? (