Skip to content

Commit 6bb41b0

Browse files
fix chat scrolling
1 parent fb9c77e commit 6bb41b0

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const ChatV2 = () => {
117117
const conversationRef = useRef<HTMLElement | null>(null)
118118
const inputFieldRef = useRef<HTMLElement | null>(null)
119119
const fileInputRef = useRef<HTMLInputElement | null>(null)
120-
120+
const endOfConversationRef = useRef<HTMLDivElement | null>(null)
121121
const [setRetryTimeout, clearRetryTimeout] = useRetryTimeout()
122122

123123
const { t, i18n } = useTranslation()
@@ -257,7 +257,7 @@ export const ChatV2 = () => {
257257
// Scrolls to bottom on initial load only
258258
if (!appContainerRef?.current || !conversationRef.current || messages.length === 0) return
259259
if (!isStreaming) {
260-
const container = appContainerRef?.current
260+
const container = appContainerRef?.current
261261
if (container) {
262262
container.scrollTo({
263263
top: container.scrollHeight,
@@ -274,18 +274,10 @@ export const ChatV2 = () => {
274274
const lastNode = conversationRef.current.lastElementChild as HTMLElement
275275

276276
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+
}
289281
}
290282
}, [isStreaming])
291283

@@ -457,6 +449,8 @@ export const ChatV2 = () => {
457449
setActiveFileSearchResult={setActiveFileSearchResult}
458450
setShowAnnotations={setShowAnnotations}
459451
/>
452+
<div ref={endOfConversationRef} style={{height: '1em'}}></div>
453+
460454
</Box>
461455

462456
<Box

0 commit comments

Comments
 (0)