Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): first scroll to button had an animation

Elian Doran2276dd17a4e7
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
index 5f1db4782c..9e42d6345e 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
@@ -165,16 +165,21 @@ export function useLlmChat(
return () => container.removeEventListener("scroll", handleScroll);
}, []);
- // Scroll to bottom when content changes, but only if user hasn't scrolled away
- const scrollToBottom = useCallback(() => {
+ // Scroll to bottom when content changes, but only if user hasn't scrolled away.
+ // Use instant scroll for message changes (includes initial load), smooth for streaming.
+ const scrollToBottom = useCallback((behavior: ScrollBehavior = "smooth") => {
if (isNearBottomRef.current) {
- messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
+ messagesEndRef.current?.scrollIntoView({ behavior });
}
}, []);
+ useEffect(() => {
+ scrollToBottom("instant");
+ }, [messages, scrollToBottom]);
+
useEffect(() => {
scrollToBottom();
- }, [messages, streamingContent, streamingThinking, scrollToBottom]);
+ }, [streamingContent, streamingThinking, scrollToBottom]);
// Load state from content object
const loadFromContent = useCallback((content: LlmChatContent) => {