From 66d104593bdc3066dbb4a9b90dea6efebf1d7a49 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Wed, 3 Jun 2026 21:57:00 +0800 Subject: [PATCH] fix(logs): avoid forced scroll-to-bottom on refresh Closes #7188 --- src/pages/logs.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pages/logs.tsx b/src/pages/logs.tsx index 43529514d..46e6fd0c6 100644 --- a/src/pages/logs.tsx +++ b/src/pages/logs.tsx @@ -61,15 +61,22 @@ const LogPage = () => { [filterLogs, isDescending], ) + const scrollRef = useRef({ isNearBottom: true, length: 0 }) const virtuosoRef = useRef(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) => ( )} + onScroll={(event) => { + const element = event.currentTarget as HTMLDivElement + scrollRef.current.isNearBottom = + element.scrollHeight - element.scrollTop - element.clientHeight <= + 20 + }} style={{ flex: 1 }} /> ) : (