From d4e9a0aff5180c649a49142330ab7964ca4155e8 Mon Sep 17 00:00:00 2001 From: Dicken Date: Sat, 13 Jun 2026 19:27:59 +0200 Subject: [PATCH] fix: Chat scrollt bei User-Wechsel und erstem Laden sofort ans Ende --- frontend/src/tools/nachrichten.jsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/tools/nachrichten.jsx b/frontend/src/tools/nachrichten.jsx index c44207a..04a5f2b 100644 --- a/frontend/src/tools/nachrichten.jsx +++ b/frontend/src/tools/nachrichten.jsx @@ -208,12 +208,20 @@ export default function Nachrichten({ toast, mobile, nav }) { // ── Scroll to bottom ───────────────────────────────────────────────────────── const prevLengthRef = useRef(0); + const prevUserRef = useRef(null); useEffect(() => { - const isFirstLoad = prevLengthRef.current === 0 && messages.length > 0; - prevLengthRef.current = messages.length; if (!bottomRef.current) return; - bottomRef.current.scrollIntoView({ behavior: isFirstLoad ? 'instant' : 'smooth' }); - }, [messages.length]); + const userChanged = prevUserRef.current !== activeUser?.id; + const isFirstLoad = prevLengthRef.current === 0 && messages.length > 0; + prevLengthRef.current = messages.length; + prevUserRef.current = activeUser?.id; + // Bei User-Wechsel oder erstem Laden: sofort ans Ende springen + if (userChanged || isFirstLoad) { + bottomRef.current.scrollIntoView({ behavior: 'instant' }); + } else if (messages.length > 0) { + bottomRef.current.scrollIntoView({ behavior: 'smooth' }); + } + }, [messages.length, activeUser?.id]); // ── Handlers ───────────────────────────────────────────────────────────────── const loadUsers = async () => {