Skip to content

Commit 41f6fce

Browse files
committed
fix(web): auto-scroll to bottom when entering brief mode
1 parent e1a43bd commit 41f6fce

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

web/src/components/AssistantChat/BriefTurnList.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ export function BriefTurnList(props: {
586586
}
587587
}, [isMobileViewport])
588588

589+
useEffect(() => {
590+
autoScrollToBottomDoneRef.current = false
591+
}, [props.session.id])
592+
589593
const renderTurnRow = useCallback((turn: ConversationTurn) => {
590594
const userPreview = turn.userPreview?.trim() ?? ''
591595
const assistantPreviewRaw = turn.assistantPreview?.trim() ?? ''
@@ -662,23 +666,31 @@ export function BriefTurnList(props: {
662666
autoScrollToBottomDoneRef.current = false
663667
return
664668
}
669+
if (props.isLoading) {
670+
return
671+
}
665672
if (autoScrollToBottomDoneRef.current) {
666673
return
667674
}
668675

669676
autoScrollToBottomDoneRef.current = true
670-
const rafId = window.requestAnimationFrame(() => {
677+
const scrollToBottom = () => {
671678
listRef.current?.scrollToIndex({
672-
index: props.turns.length - 1,
679+
index: 'LAST',
673680
align: 'end',
674681
behavior: 'auto'
675682
})
676-
})
683+
}
684+
685+
scrollToBottom()
686+
const rafId = window.requestAnimationFrame(scrollToBottom)
687+
const timeoutId = window.setTimeout(scrollToBottom, 120)
677688

678689
return () => {
679690
window.cancelAnimationFrame(rafId)
691+
window.clearTimeout(timeoutId)
680692
}
681-
}, [props.turns.length])
693+
}, [props.isLoading, props.turns.length])
682694

683695
return (
684696
<>

web/src/routes/groups/detail.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,22 +1871,33 @@ function GroupBriefTurnList(props: {
18711871
}
18721872
}, [isMobileViewport])
18731873

1874+
useEffect(() => {
1875+
autoScrollToBottomDoneRef.current = false
1876+
}, [props.groupId])
1877+
18741878
useEffect(() => {
18751879
if (props.turns.length === 0) {
18761880
autoScrollToBottomDoneRef.current = false
18771881
return
18781882
}
1883+
if (props.isLoading) {
1884+
return
1885+
}
18791886
if (autoScrollToBottomDoneRef.current) {
18801887
return
18811888
}
18821889
autoScrollToBottomDoneRef.current = true
1883-
const rafId = window.requestAnimationFrame(() => {
1884-
listRef.current?.scrollToIndex({ index: props.turns.length - 1, align: 'end', behavior: 'auto' })
1885-
})
1890+
const scrollToBottom = () => {
1891+
listRef.current?.scrollToIndex({ index: 'LAST', align: 'end', behavior: 'auto' })
1892+
}
1893+
scrollToBottom()
1894+
const rafId = window.requestAnimationFrame(scrollToBottom)
1895+
const timeoutId = window.setTimeout(scrollToBottom, 120)
18861896
return () => {
18871897
window.cancelAnimationFrame(rafId)
1898+
window.clearTimeout(timeoutId)
18881899
}
1889-
}, [props.turns.length])
1900+
}, [props.isLoading, props.turns.length])
18901901

18911902
return (
18921903
<>

0 commit comments

Comments
 (0)