Skip to content

Commit 09e054c

Browse files
(fix/scroll) bring back arrowDown button, smoother scroll
1 parent 23f648f commit 09e054c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

frontend/src/conversation/ConversationMessages.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, useEffect, useRef, useState, useCallback } from 'react';
1+
import { Fragment, useEffect, useRef, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33

44
import ArrowDown from '../assets/arrow-down.svg';
@@ -38,7 +38,7 @@ export default function ConversationMessages({
3838
const { t } = useTranslation();
3939

4040
const conversationRef = useRef<HTMLDivElement>(null);
41-
const atLast = useRef(true);
41+
const [atLast,setAtLast] = useState(true);
4242
const [eventInterrupt, setEventInterrupt] = useState(false);
4343

4444
const handleUserInterruption = () => {
@@ -47,12 +47,11 @@ export default function ConversationMessages({
4747
}
4848
};
4949

50-
// Remove Mermaid tracking code that was here
5150

5251
const scrollIntoView = () => {
5352
if (!conversationRef?.current || eventInterrupt) return;
5453

55-
setTimeout(() => {
54+
requestAnimationFrame(() => {
5655
if (!conversationRef?.current) return;
5756

5857
if (status === 'idle' || !queries[queries.length - 1]?.response) {
@@ -63,14 +62,14 @@ export default function ConversationMessages({
6362
} else {
6463
conversationRef.current.scrollTop = conversationRef.current.scrollHeight;
6564
}
66-
}, 100); // Small timeout to allow images to render
65+
});
6766
};
6867

6968
const checkScroll = () => {
7069
const el = conversationRef.current;
7170
if (!el) return;
7271
const isBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 10;
73-
atLast.current = isBottom;
72+
setAtLast(isBottom);
7473
};
7574

7675
useEffect(() => {
@@ -151,9 +150,9 @@ export default function ConversationMessages({
151150
ref={conversationRef}
152151
onWheel={handleUserInterruption}
153152
onTouchMove={handleUserInterruption}
154-
className="flex justify-center w-full overflow-y-auto h-full sm:pt-12"
153+
className="flex justify-center w-full overflow-y-auto h-full sm:pt-12 will-change-scroll"
155154
>
156-
{queries.length > 0 && !atLast.current && (
155+
{queries.length > 0 && !atLast && (
157156
<button
158157
onClick={scrollIntoView}
159158
aria-label="scroll to bottom"

0 commit comments

Comments
 (0)