@@ -188,21 +188,26 @@ export class ChatComponent {
188188 /** Track message count to trigger auto-scroll */
189189 private readonly messageCount = computed ( ( ) => this . ref ( ) . messages ( ) . length ) ;
190190
191+ private prevMessageCount = 0 ;
192+
191193 constructor ( ) {
192- // Auto-scroll to bottom when new messages arrive.
193- // Only scrolls if user is already near the bottom (within 150px),
194- // so reading earlier messages isn't interrupted.
194+ // Auto-scroll to bottom:
195+ // - Always scroll when message count increases (new message sent/received)
196+ // - During streaming partials, only scroll if user is near bottom
195197 effect ( ( ) => {
196- this . messageCount ( ) ; // track
198+ const count = this . messageCount ( ) ;
197199 this . ref ( ) . isLoading ( ) ; // track
198200 const el = this . scrollContainer ( ) ?. nativeElement ;
199- if ( el ) {
200- const isNearBottom = el . scrollHeight - el . scrollTop - el . clientHeight < 150 ;
201- if ( isNearBottom ) {
202- requestAnimationFrame ( ( ) => {
203- el . scrollTo ( { top : el . scrollHeight , behavior : 'smooth' } ) ;
204- } ) ;
205- }
201+ if ( ! el ) return ;
202+
203+ const isNewMessage = count !== this . prevMessageCount ;
204+ this . prevMessageCount = count ;
205+
206+ const isNearBottom = el . scrollHeight - el . scrollTop - el . clientHeight < 150 ;
207+ if ( isNewMessage || isNearBottom ) {
208+ requestAnimationFrame ( ( ) => {
209+ el . scrollTo ( { top : el . scrollHeight , behavior : isNewMessage ? 'instant' : 'smooth' } ) ;
210+ } ) ;
206211 }
207212 } ) ;
208213 }
0 commit comments