@@ -397,7 +397,7 @@ import {
397397import { environmentShell , useEnvironmentShellHasSnapshot } from "../state/shell" ;
398398import { ChatComposer , type ChatComposerHandle } from "./chat/ChatComposer" ;
399399import { createPageScrollController , type PageScrollKey } from "./chat/pageScrollController" ;
400- import { isTimelineScrollTarget } from "./chat/timelineScrollTarget" ;
400+ import { createUpwardScrollDetector , isTimelineScrollTarget } from "./chat/timelineScrollTarget" ;
401401import { DraftHeroHeadline } from "./chat/DraftHeroHeadline" ;
402402import { ExpandedImageDialogHost , openExpandedImagePreview } from "./chat/ExpandedImageDialog" ;
403403import {
@@ -4295,6 +4295,33 @@ export default function ChatView(props: ChatViewProps) {
42954295 break ;
42964296 }
42974297 } ;
4298+ // Input inside an embedded frame reaches none of the listeners above,
4299+ // but its scroll still chains out to the timeline (#17056).
4300+ const scrolledUp = createUpwardScrollDetector ( {
4301+ top : scrollNode . scrollTop ,
4302+ height : scrollNode . scrollHeight ,
4303+ } ) ;
4304+ const handleScroll = ( ) => {
4305+ if (
4306+ scrolledUp ( {
4307+ top : scrollNode . scrollTop ,
4308+ height : scrollNode . scrollHeight ,
4309+ programmatic :
4310+ positionedTimelineAnchorRef . current !== null &&
4311+ positionedTimelineAnchorRef . current !== settledTimelineAnchorRef . current ,
4312+ } ) &&
4313+ timelineScrollModeRef . current !== "free-scrolling" &&
4314+ // LegendList updates its scroll state on the next animation frame.
4315+ resolveTimelineIsAtEnd ( {
4316+ contentLength : scrollNode . scrollHeight ,
4317+ scroll : scrollNode . scrollTop ,
4318+ scrollLength : scrollNode . clientHeight ,
4319+ } ) === false
4320+ ) {
4321+ handleManualNavigation ( ) ;
4322+ }
4323+ } ;
4324+ scrollNode . addEventListener ( "scroll" , handleScroll , { passive : true } ) ;
42984325 scrollNode . addEventListener ( "wheel" , handleWheel , {
42994326 passive : true ,
43004327 } ) ;
@@ -4306,6 +4333,7 @@ export default function ChatView(props: ChatViewProps) {
43064333 } ) ;
43074334 document . addEventListener ( "keydown" , handleKeyDown ) ;
43084335 removeListeners = ( ) => {
4336+ scrollNode . removeEventListener ( "scroll" , handleScroll ) ;
43094337 scrollNode . removeEventListener ( "wheel" , handleWheel ) ;
43104338 scrollNode . removeEventListener ( "touchmove" , handleTouchMove ) ;
43114339 scrollNode . removeEventListener ( "pointerdown" , handlePointerDown ) ;
@@ -4351,30 +4379,22 @@ export default function ChatView(props: ChatViewProps) {
43514379 }
43524380 return ;
43534381 }
4354- const scrollNode = list . getScrollableNode ( ) ;
4355- let finished = false ;
4356- const finishAnimatedPositioning = ( ) => {
4357- if ( finished ) {
4358- return ;
4359- }
4360- finished = true ;
4361- window . clearTimeout ( fallbackTimer ) ;
4362- scrollNode . removeEventListener ( "scrollend" , finishAnimatedPositioning ) ;
4363- if ( positionedTimelineAnchorRef . current !== messageId ) {
4364- return ;
4365- }
4366- const scrollOffset = list . getState ( ) . scroll ;
4367- void list . scrollToOffset ( { offset : scrollOffset , animated : false } ) ;
4368- settledTimelineAnchorRef . current = messageId ;
4369- } ;
4370- const fallbackTimer = window . setTimeout ( finishAnimatedPositioning , 750 ) ;
4371- scrollNode . addEventListener ( "scrollend" , finishAnimatedPositioning , { once : true } ) ;
4372- void list . scrollToIndex ( {
4373- index : anchorIndex ,
4374- animated : ! window . matchMedia ( "(prefers-reduced-motion: reduce)" ) . matches ,
4375- viewPosition : 0 ,
4376- viewOffset : CHAT_LIST_ANCHOR_OFFSET ,
4377- } ) ;
4382+ // LegendList waits for queued layout and the animation before resolving.
4383+ void list
4384+ . scrollToIndex ( {
4385+ index : anchorIndex ,
4386+ animated : ! window . matchMedia ( "(prefers-reduced-motion: reduce)" ) . matches ,
4387+ viewPosition : 0 ,
4388+ viewOffset : CHAT_LIST_ANCHOR_OFFSET ,
4389+ } )
4390+ . then ( ( ) => {
4391+ if (
4392+ legendListRef . current === list &&
4393+ positionedTimelineAnchorRef . current === messageId
4394+ ) {
4395+ settledTimelineAnchorRef . current = messageId ;
4396+ }
4397+ } ) ;
43784398 } ) ;
43794399 } ;
43804400 requestAnimationFrame ( ( ) => positionAnchor ( 12 ) ) ;
0 commit comments