mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
Add cleanup function to setTimeout in useEffect to prevent memory leaks
Co-authored-by: GTheMachine <156854865+GTheMachine@users.noreply.github.com>
This commit is contained in:
@@ -100,9 +100,10 @@ export function InterviewView() {
|
|||||||
|
|
||||||
// Auto-scroll to bottom when messages change
|
// Auto-scroll to bottom when messages change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let timeoutId: NodeJS.Timeout | undefined;
|
||||||
if (messagesContainerRef.current) {
|
if (messagesContainerRef.current) {
|
||||||
// Use a small delay to ensure DOM is updated
|
// Use a small delay to ensure DOM is updated
|
||||||
setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
if (messagesContainerRef.current) {
|
if (messagesContainerRef.current) {
|
||||||
messagesContainerRef.current.scrollTo({
|
messagesContainerRef.current.scrollTo({
|
||||||
top: messagesContainerRef.current.scrollHeight,
|
top: messagesContainerRef.current.scrollHeight,
|
||||||
@@ -111,6 +112,11 @@ export function InterviewView() {
|
|||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [messages]);
|
}, [messages]);
|
||||||
|
|
||||||
// Auto-focus input
|
// Auto-focus input
|
||||||
|
|||||||
Reference in New Issue
Block a user