Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): fix autoscrolling for next chat and chat regeneration (Issues #501, #500) #801

11 changes: 2 additions & 9 deletions apps/chat/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const ChatView = memo(() => {
const nextMessageBoxRef = useRef<HTMLDivElement | null>(null);
const [inputHeight, setInputHeight] = useState<number>(142);
const [notAllowedType, setNotAllowedType] = useState<EntityType | null>(null);
const isSentRef = useRef(false);
const disableAutoScrollTimeoutRef = useRef<ReturnType<typeof setTimeout>>();

const showReplayControls = useMemo(() => {
Expand Down Expand Up @@ -253,11 +252,6 @@ export const ChatView = memo(() => {
setIsShowChatSettings(false);

if (selectedConversations.length > 0) {
if (isSentRef.current) {
handleScroll();
isSentRef.current = false;
}

const mergedMessages: MergedMessages[] = [];
for (let i = 0; i < selectedConversations[0].messages.length; i++) {
if (selectedConversations[0].messages[i].role === Role.System) continue;
Expand All @@ -270,6 +264,8 @@ export const ChatView = memo(() => {
]),
);
}

handleScroll();
setMergedMessages([...mergedMessages]);
}

Expand Down Expand Up @@ -466,7 +462,6 @@ export const ChatView = memo(() => {
activeReplayIndex: 0,
}),
);
isSentRef.current = true;
},
[dispatch, selectedConversations],
);
Expand All @@ -484,7 +479,6 @@ export const ChatView = memo(() => {
activeReplayIndex: 0,
}),
);
isSentRef.current = true;
}, [dispatch, selectedConversations]);

const onEditMessage = useCallback(
Expand All @@ -498,7 +492,6 @@ export const ChatView = memo(() => {
activeReplayIndex: 0,
}),
);
isSentRef.current = true;
},
[dispatch, selectedConversations],
);
Expand Down
Loading