From 44dd8c692607d2a510e6dc953dad58524f770fa7 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Sun, 3 Oct 2021 20:42:27 +0800 Subject: [PATCH] Fix: log scroll ux --- src/containers/Logs/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/containers/Logs/index.tsx b/src/containers/Logs/index.tsx index 7ff976e..8fe16ff 100644 --- a/src/containers/Logs/index.tsx +++ b/src/containers/Logs/index.tsx @@ -14,12 +14,14 @@ export default function Logs () { const { translation } = useI18n() const { t } = translation('Logs') const logsStreamReader = useLogsStreamReader() + const scrollHeightRef = useRef(listRef.current?.scrollHeight ?? 0) useLayoutEffect(() => { const ul = listRef.current - if (ul != null) { - ul.scrollTop = ul.scrollHeight + if (ul != null && scrollHeightRef.current === (ul.scrollTop + ul.clientHeight)) { + ul.scrollTop = ul.scrollHeight - ul.clientHeight } + scrollHeightRef.current = ul?.scrollHeight ?? 0 }) useEffect(() => {