| .. | .. |
|---|
| 20 | 20 | |
|---|
| 21 | 21 | useEffect(() => { |
|---|
| 22 | 22 | if (messages.length > 0) { |
|---|
| 23 | | - // If the message count changed by more than 1, it's a session switch — |
|---|
| 24 | | - // snap to bottom instantly instead of visibly scrolling down. |
|---|
| 23 | + // If the message count changed by more than 1, it's a session switch or |
|---|
| 24 | + // initial load — snap to bottom instantly instead of visibly scrolling. |
|---|
| 25 | 25 | const delta = Math.abs(messages.length - prevLengthRef.current); |
|---|
| 26 | 26 | const animated = delta === 1; |
|---|
| 27 | + const delay = delta > 1 ? 200 : 50; |
|---|
| 27 | 28 | setTimeout(() => { |
|---|
| 28 | 29 | listRef.current?.scrollToEnd({ animated }); |
|---|
| 29 | | - }, 50); |
|---|
| 30 | + }, delay); |
|---|
| 30 | 31 | } |
|---|
| 31 | 32 | prevLengthRef.current = messages.length; |
|---|
| 32 | 33 | }, [messages.length, isTyping, lastContent]); |
|---|