fix(logs): avoid forced scroll-to-bottom on refresh

Closes #7188
This commit is contained in:
Tunglies
2026-06-04 12:33:27 +08:00
parent bc2149c66d
commit 66d104593b
+15 -2
View File
@@ -61,15 +61,22 @@ const LogPage = () => {
[filterLogs, isDescending],
)
const scrollRef = useRef({ isNearBottom: true, length: 0 })
const virtuosoRef = useRef<VirtualListHandle>(null)
useEffect(() => {
if (!isDescending && filteredLogs.length > 0) {
if (
!isDescending &&
filteredLogs.length > scrollRef.current.length &&
scrollRef.current.isNearBottom
) {
virtuosoRef.current?.scrollToIndex(filteredLogs.length - 1, {
behavior: 'smooth',
})
}
}, [filteredLogs.length, isDescending])
scrollRef.current.length = filteredLogs.length
}, [isDescending, filteredLogs.length])
const handleLogLevelChange = (newLevel: LogFilter) => {
setClashLog((pre) => ({ ...pre!, logFilter: newLevel }))
@@ -188,6 +195,12 @@ const LogPage = () => {
renderItem={(i) => (
<LogItem value={filteredLogs[i]} searchState={searchState} />
)}
onScroll={(event) => {
const element = event.currentTarget as HTMLDivElement
scrollRef.current.isNearBottom =
element.scrollHeight - element.scrollTop - element.clientHeight <=
20
}}
style={{ flex: 1 }}
/>
) : (