Skip to content

Commit f8294fb

Browse files
authored
New option to allow disabling auto-scroll of assistant messages (Chainlit#2724)
<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds a new config option to control auto-scrolling for assistant messages. Default is on, so behavior stays the same unless you disable it. - **New Features** - Added assistant_message_autoscroll (default true) to backend FeaturesSettings and config. - Updated types to include assistant_message_autoscroll. - ScrollContainer now respects this flag; Chat and Copilot pass it through. - **Migration** - To disable: set assistant_message_autoscroll: false in the Chainlit config. <sup>Written for commit 7b09d58. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
1 parent f4bcb69 commit f8294fb

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

backend/chainlit/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
# Autoscroll new user messages at the top of the window
100100
user_message_autoscroll = true
101101
102+
# Autoscroll new assistant messages
103+
assistant_message_autoscroll = true
104+
102105
# Automatically tag threads with the current chat profile (if a chat profile is used)
103106
auto_tag_thread = true
104107
@@ -308,6 +311,7 @@ class FeaturesSettings(BaseModel):
308311
slack: SlackFeature = Field(default_factory=SlackFeature)
309312
latex: bool = False
310313
user_message_autoscroll: bool = True
314+
assistant_message_autoscroll: bool = True
311315
unsafe_allow_html: bool = False
312316
auto_tag_thread: bool = True
313317
edit_message: bool = True

frontend/src/components/chat/ScrollContainer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Button } from '@/components/ui/button';
1414

1515
interface Props {
1616
autoScrollUserMessage?: boolean;
17+
autoScrollAssistantMessage?: boolean;
1718
autoScrollRef?: MutableRefObject<boolean>;
1819
children: React.ReactNode;
1920
className?: string;
@@ -22,6 +23,7 @@ interface Props {
2223
export default function ScrollContainer({
2324
autoScrollRef,
2425
autoScrollUserMessage,
26+
autoScrollAssistantMessage,
2527
children,
2628
className
2729
}: Props) {
@@ -63,13 +65,13 @@ export default function ScrollContainer({
6365
// Scroll to position the message at the top
6466
if (afterMessagesHeight === 0) {
6567
scrollToPosition();
66-
} else if (autoScrollRef?.current) {
68+
} else if (autoScrollAssistantMessage && autoScrollRef?.current) {
6769
ref.current.scrollTop = ref.current.scrollHeight;
6870
}
69-
} else if (autoScrollRef?.current) {
71+
} else if (autoScrollAssistantMessage && autoScrollRef?.current) {
7072
ref.current.scrollTop = ref.current.scrollHeight;
7173
}
72-
}, [autoScrollUserMessage, autoScrollRef]);
74+
}, [autoScrollUserMessage, autoScrollAssistantMessage, autoScrollRef]);
7375

7476
// Find and set a ref to the last user message element
7577
useEffect(() => {

frontend/src/components/chat/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ const Chat = () => {
213213
<ErrorBoundary>
214214
<ScrollContainer
215215
autoScrollUserMessage={config?.features?.user_message_autoscroll}
216+
autoScrollAssistantMessage={
217+
config?.features?.assistant_message_autoscroll
218+
}
216219
autoScrollRef={autoScrollRef}
217220
>
218221
<div

libs/copilot/src/chat/body.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ const Chat = () => {
164164
<ErrorBoundary>
165165
<ScrollContainer
166166
autoScrollUserMessage={config?.features?.user_message_autoscroll}
167+
autoScrollAssistantMessage={
168+
config?.features?.assistant_message_autoscroll
169+
}
167170
autoScrollRef={autoScrollRef}
168171
>
169172
<div

libs/react-client/src/types/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface IChainlitConfig {
6666
audio: IAudioConfig;
6767
unsafe_allow_html?: boolean;
6868
user_message_autoscroll?: boolean;
69+
assistant_message_autoscroll?: boolean;
6970
latex?: boolean;
7071
edit_message?: boolean;
7172
mcp?: {

0 commit comments

Comments
 (0)