@@ -491,11 +491,34 @@ export const AutoCompactWarning: AppStory = {
491491 canvas . getByText ( / a c c e s s t o k e n e x p i r e s i n 1 5 m i n u t e s / ) ;
492492 } ) ;
493493
494- // Wait a bit for auto-scroll to settle, then scroll up
495- await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
496- const messageWindow = canvasElement . querySelector ( '[data-testid="message-window"]' ) ;
494+ // Wait for initial auto-scroll and all ResizeObserver callbacks to complete
495+ await new Promise ( ( r ) => setTimeout ( r , 500 ) ) ;
496+
497+ const messageWindow = canvasElement . querySelector (
498+ '[data-testid="message-window"]'
499+ ) as HTMLElement | null ;
497500 if ( messageWindow ) {
498- messageWindow . scrollTop = messageWindow . scrollHeight - messageWindow . clientHeight - 150 ;
501+ // Simulate user scroll interaction multiple times to ensure auto-scroll is disabled.
502+ // The useAutoScroll hook only processes scroll as "user-initiated" if it happens
503+ // within 100ms of a wheel/touch event. We need to:
504+ // 1. Mark user interaction via wheel event
505+ // 2. Scroll up (which disables auto-scroll)
506+ // 3. Wait and repeat to ensure the state sticks
507+ for ( let i = 0 ; i < 3 ; i ++ ) {
508+ messageWindow . dispatchEvent ( new WheelEvent ( "wheel" , { bubbles : true , deltaY : - 100 } ) ) ;
509+ // Scroll to show ~200px of content above the input area
510+ const targetScroll = Math . max ( 0 , messageWindow . scrollHeight - messageWindow . clientHeight - 200 ) ;
511+ messageWindow . scrollTop = targetScroll ;
512+ messageWindow . dispatchEvent ( new Event ( "scroll" , { bubbles : true } ) ) ;
513+ await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
514+ }
515+
516+ // Final wait to let any pending ResizeObserver callbacks fire and see disabled auto-scroll
517+ await new Promise ( ( r ) => setTimeout ( r , 200 ) ) ;
518+
519+ // Set final scroll position
520+ const finalScroll = Math . max ( 0 , messageWindow . scrollHeight - messageWindow . clientHeight - 200 ) ;
521+ messageWindow . scrollTop = finalScroll ;
499522 }
500523 } ,
501524 parameters : {
0 commit comments