Skip to content

Commit 83292a4

Browse files
authored
📜 refactor: Enhance Auto Scroll Speed and UseEffect Cleanup (#1591)
1 parent a7c5457 commit 83292a4

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

client/src/hooks/Messages/useMessageHelpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import copy from 'copy-to-clipboard';
2-
import { useEffect, useRef } from 'react';
2+
import { useEffect, useRef, useCallback } from 'react';
33
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
44
import type { TMessage } from 'librechat-data-provider';
55
import type { TMessageProps } from '~/common';
@@ -43,13 +43,13 @@ export default function useMessageHelpers(props: TMessageProps) {
4343
const enterEdit = (cancel?: boolean) =>
4444
setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId);
4545

46-
const handleScroll = () => {
46+
const handleScroll = useCallback(() => {
4747
if (isSubmitting) {
4848
setAbortScroll(true);
4949
} else {
5050
setAbortScroll(false);
5151
}
52-
};
52+
}, [isSubmitting, setAbortScroll]);
5353

5454
const icon = Icon({
5555
...conversation,

client/src/hooks/Messages/useMessageScrolling.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export default function useMessageScrolling(messagesTree?: TMessage[] | null) {
6363
if (isSubmitting && scrollToBottom && !abortScroll) {
6464
scrollToBottom();
6565
}
66+
67+
return () => {
68+
if (abortScroll) {
69+
scrollToBottom && scrollToBottom?.cancel();
70+
}
71+
};
6672
}, [isSubmitting, messagesTree, scrollToBottom, abortScroll]);
6773

6874
useEffect(() => {

client/src/hooks/useScrollToRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function useScrollToRef({ targetRef, callback, smoothCallback }:
1717

1818
// eslint-disable-next-line react-hooks/exhaustive-deps
1919
const scrollToRef = useCallback(
20-
throttle(() => logAndScroll('instant', callback), 450, { leading: true }),
20+
throttle(() => logAndScroll('instant', callback), 250, { leading: true }),
2121
[targetRef],
2222
);
2323

0 commit comments

Comments
 (0)