@@ -117,7 +117,7 @@ export const ChatV2 = () => {
117
117
const conversationRef = useRef < HTMLElement | null > ( null )
118
118
const inputFieldRef = useRef < HTMLElement | null > ( null )
119
119
const fileInputRef = useRef < HTMLInputElement | null > ( null )
120
-
120
+ const endOfConversationRef = useRef < HTMLDivElement | null > ( null )
121
121
const [ setRetryTimeout , clearRetryTimeout ] = useRetryTimeout ( )
122
122
123
123
const { t, i18n } = useTranslation ( )
@@ -257,7 +257,7 @@ export const ChatV2 = () => {
257
257
// Scrolls to bottom on initial load only
258
258
if ( ! appContainerRef ?. current || ! conversationRef . current || messages . length === 0 ) return
259
259
if ( ! isStreaming ) {
260
- const container = appContainerRef ?. current
260
+ const container = appContainerRef ?. current
261
261
if ( container ) {
262
262
container . scrollTo ( {
263
263
top : container . scrollHeight ,
@@ -274,18 +274,10 @@ export const ChatV2 = () => {
274
274
const lastNode = conversationRef . current . lastElementChild as HTMLElement
275
275
276
276
if ( lastNode . classList . contains ( 'message-role-assistant' ) && isStreaming ) {
277
- const container = appContainerRef . current
278
-
279
- const containerRect = container . getBoundingClientRect ( )
280
- const lastNodeRect = lastNode . getBoundingClientRect ( )
281
-
282
- const scrollTopPadding = 200
283
- const scrollOffset = lastNodeRect . top - containerRect . top + container . scrollTop - scrollTopPadding
284
-
285
- container . scrollTo ( {
286
- top : scrollOffset ,
287
- behavior : 'smooth' ,
288
- } )
277
+ if ( endOfConversationRef ?. current )
278
+ {
279
+ endOfConversationRef . current . scrollIntoView ( { behavior : 'smooth' } )
280
+ }
289
281
}
290
282
} , [ isStreaming ] )
291
283
@@ -457,6 +449,8 @@ export const ChatV2 = () => {
457
449
setActiveFileSearchResult = { setActiveFileSearchResult }
458
450
setShowAnnotations = { setShowAnnotations }
459
451
/>
452
+ < div ref = { endOfConversationRef } style = { { height : '1em' } } > </ div >
453
+
460
454
</ Box >
461
455
462
456
< Box
0 commit comments