Skip to content

Commit 9b7f401

Browse files
committed
Cleanup on ChatPage/MessagesDisply
1 parent 0fd268d commit 9b7f401

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

web/src/app/chat/components/ChatPage.tsx

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -362,39 +362,6 @@ export function ChatPage({
362362
}
363363
}, [setMessage, setCurrentMessageFiles]);
364364

365-
const clientScrollToBottom = useCallback((fast?: boolean) => {
366-
waitForScrollRef.current = true;
367-
368-
setTimeout(() => {
369-
if (!endDivRef.current || !scrollableDivRef.current) {
370-
console.error("endDivRef or scrollableDivRef not found");
371-
return;
372-
}
373-
374-
const rect = endDivRef.current.getBoundingClientRect();
375-
const isVisible = rect.top >= 0 && rect.bottom <= window.innerHeight;
376-
377-
if (isVisible) return;
378-
379-
// Check if all messages are currently rendered
380-
// If all messages are already rendered, scroll immediately
381-
endDivRef.current.scrollIntoView({
382-
behavior: fast ? "auto" : "smooth",
383-
});
384-
385-
if (chatSessionIdRef.current) {
386-
useChatSessionStore
387-
.getState()
388-
.updateHasPerformedInitialScroll(chatSessionIdRef.current, true);
389-
}
390-
}, 50);
391-
392-
// Reset waitForScrollRef after 1.5 seconds
393-
setTimeout(() => {
394-
waitForScrollRef.current = false;
395-
}, 1500);
396-
}, []);
397-
398365
const debounceNumber = 100; // time for debouncing
399366

400367
// handle re-sizing of the text area
@@ -490,6 +457,40 @@ export function ChatPage({
490457
(state) => state.updateCurrentChatSessionSharedStatus
491458
);
492459

460+
const clientScrollToBottom = useCallback(
461+
(fast?: boolean) => {
462+
waitForScrollRef.current = true;
463+
464+
setTimeout(() => {
465+
if (!endDivRef.current || !scrollableDivRef.current) {
466+
console.error("endDivRef or scrollableDivRef not found");
467+
return;
468+
}
469+
470+
const rect = endDivRef.current.getBoundingClientRect();
471+
const isVisible = rect.top >= 0 && rect.bottom <= window.innerHeight;
472+
473+
if (isVisible) return;
474+
475+
// Check if all messages are currently rendered
476+
// If all messages are already rendered, scroll immediately
477+
endDivRef.current.scrollIntoView({
478+
behavior: fast ? "auto" : "smooth",
479+
});
480+
481+
if (chatSessionIdRef.current) {
482+
updateHasPerformedInitialScroll(chatSessionIdRef.current, true);
483+
}
484+
}, 50);
485+
486+
// Reset waitForScrollRef after 1.5 seconds
487+
setTimeout(() => {
488+
waitForScrollRef.current = false;
489+
}, 1500);
490+
},
491+
[updateHasPerformedInitialScroll]
492+
);
493+
493494
const { onSubmit, stopGenerating, handleMessageSpecificFileUpload } =
494495
useChatController({
495496
filterManager,

web/src/app/chat/components/MessagesDisplay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { RefObject, useCallback, useMemo } from "react";
2-
import { CitationMap, Message } from "../interfaces";
2+
import { Message } from "../interfaces";
33
import { OnyxDocument, MinimalOnyxDocument } from "@/lib/search/interfaces";
44
import { MemoizedHumanMessage } from "../message/MemoizedHumanMessage";
55
import { ErrorBanner } from "../message/Resubmit";

0 commit comments

Comments
 (0)