From 858f4dce1d9edb3abe0193f9171e8a4946c6f621 Mon Sep 17 00:00:00 2001 From: M57 <41645758+Hy4ri@users.noreply.github.com> Date: Tue, 23 Jun 2026 12:35:29 +0300 Subject: [PATCH] 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 --- app/src/main/java/com/m57/hermescontrol/ui/chat/ChatScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/m57/hermescontrol/ui/chat/ChatScreen.kt b/app/src/main/java/com/m57/hermescontrol/ui/chat/ChatScreen.kt index 8f3cf332..6f3a3bc5 100644 --- a/app/src/main/java/com/m57/hermescontrol/ui/chat/ChatScreen.kt +++ b/app/src/main/java/com/m57/hermescontrol/ui/chat/ChatScreen.kt @@ -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) +