@@ -96,27 +96,6 @@ export const snapScrollToBottom = (node: HTMLElement, dependency: MaybeScrollDep
9696 }
9797 } ;
9898
99- const nextFrame = ( ) =>
100- new Promise < void > ( ( resolve ) => {
101- if ( typeof requestAnimationFrame === "function" ) requestAnimationFrame ( ( ) => resolve ( ) ) ;
102- else resolve ( ) ;
103- } ) ;
104-
105- // content-visibility:auto messages start at their contain-intrinsic-size
106- // estimate, so a single scrollToBottom can land short of the true bottom: as
107- // the bottom messages scroll into view they render at full height and grow
108- // scrollHeight. Re-scroll across a few frames to converge, stopping early once
109- // we reach the bottom or the user takes over. Bounded so it can never loop
110- // indefinitely.
111- const scrollToBottomConverged = async ( behavior : ScrollBehavior = "instant" ) => {
112- scrollToBottom ( behavior ) ;
113- for ( let i = 0 ; i < 5 ; i ++ ) {
114- await nextFrame ( ) ;
115- if ( isDetached || userScrolling || isAtBottom ( ) ) return ;
116- scrollToBottom ( "instant" ) ;
117- }
118- } ;
119-
12099 const scheduleUserScrollEndCheck = ( ) => {
121100 userScrolling = true ;
122101 clearUserScrollTimeout ( ) ;
@@ -197,16 +176,7 @@ export const snapScrollToBottom = (node: HTMLElement, dependency: MaybeScrollDep
197176 clearUserScrollTimeout ( ) ;
198177
199178 await tick ( ) ;
200- const behavior = getScrollBehavior ( newDependency ) ;
201- // Conversation switch/load uses "instant" and renders content-visibility
202- // messages from their size estimate; converge to the real bottom. The
203- // "smooth" path (new user message) is handled by ChatWindow's spacer
204- // observer, so keep its single smooth scroll.
205- if ( behavior === "instant" ) {
206- await scrollToBottomConverged ( behavior ) ;
207- } else {
208- scrollToBottom ( behavior ) ;
209- }
179+ scrollToBottom ( getScrollBehavior ( newDependency ) ) ;
210180 return true ;
211181 }
212182
@@ -314,7 +284,7 @@ export const snapScrollToBottom = (node: HTMLElement, dependency: MaybeScrollDep
314284 if ( dependency ) {
315285 void ( async ( ) => {
316286 await tick ( ) ;
317- await scrollToBottomConverged ( ) ;
287+ scrollToBottom ( ) ;
318288 } ) ( ) ;
319289 }
320290
0 commit comments