fix: optimize autoscroll on message stream (resolves #274) (#314)

Previously, the auto-scroll LaunchedEffect was keyed to `state.streamingMessage?.content?.length`, which resulted in the scroll animation coroutine being cancelled and restarted for every single token received during message generation. This caused a heavy performance hit and interrupted smooth scrolling.

This commit updates the `LaunchedEffect` key to use `state.streamingMessage != null` instead. The scroll-to-bottom logic now appropriately initiates when a message *begins* streaming (or finishes thinking), while avoiding continuous job restarts as the payload streams in.

Resolves #274
This commit is contained in:
M57 authored and GitHub committed 2026-06-23 12:35:29 +03:00
1 parent 4faa3a156f
commit 858f4dce1d
1 file changed
+1 -1
@@ -212,7 +212,7 @@ fun ChatScreen(
}
// Auto-scroll to bottom on new messages
LaunchedEffect(state.messages.size, state.streamingMessage?.content?.length, state.isThinking) {
LaunchedEffect(state.messages.size, state.streamingMessage != null, state.isThinking) {
val totalItems =
state.messages.size +
(if (state.streamingMessage != null) 1 else 0) +