From 95cfce6927ff407dcbd82783e7b4a0e1d8a6ed3c Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 29 Jun 2021 19:35:49 +0300 Subject: [PATCH] Message List: Fix losing scroll position in unread chats (follow-up) --- src/components/middle/MessageList.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 2bd8c5fa..45e31aa4 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -471,8 +471,11 @@ const MessageList: FC = ({ } else if (anchor) { const newAnchorTop = anchor.getBoundingClientRect().top; newScrollTop = scrollTop + (newAnchorTop - (anchorTopRef.current || 0)); - } else if (unreadDivider && !scrollOffset) { - newScrollTop = unreadDivider.offsetTop - (hasTools ? UNREAD_DIVIDER_TOP_WITH_TOOLS : UNREAD_DIVIDER_TOP); + } else if (unreadDivider) { + newScrollTop = Math.min( + unreadDivider.offsetTop - (hasTools ? UNREAD_DIVIDER_TOP_WITH_TOOLS : UNREAD_DIVIDER_TOP), + scrollHeight - scrollOffset, + ); } else { newScrollTop = scrollHeight - scrollOffset; }