diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 047607d4e67..35f2804668b 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -3,8 +3,8 @@ import React, { useState, useRef, useEffect, - useLayoutEffect, useMemo, + useCallback, } from "react"; import SendWhiteIcon from "../icons/send-white.svg"; @@ -341,15 +341,15 @@ function useScrollToBottom() { // for auto-scroll const scrollRef = useRef(null); const [autoScroll, setAutoScroll] = useState(true); - const scrollToBottom = () => { + const scrollToBottom = useCallback(() => { const dom = scrollRef.current; if (dom) { - setTimeout(() => (dom.scrollTop = dom.scrollHeight), 1); + requestAnimationFrame(() => dom.scrollTo(0, dom.scrollHeight)); } - }; + }, []); // auto scroll - useLayoutEffect(() => { + useEffect(() => { autoScroll && scrollToBottom(); });