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 () => {