From f3cb4b74c55f13a3e6ca85567a4b213b139e3bdf Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Thu, 16 Jul 2026 10:41:24 +0200 Subject: [PATCH] fix: re-anchor new messages divider at last read when tabbing out --- .changeset/fix-new-messages-divider-refocus.md | 5 +++++ src/app/features/room/RoomTimeline.tsx | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-new-messages-divider-refocus.md diff --git a/.changeset/fix-new-messages-divider-refocus.md b/.changeset/fix-new-messages-divider-refocus.md new file mode 100644 index 000000000..8dd08735b --- /dev/null +++ b/.changeset/fix-new-messages-divider-refocus.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +Fix the new messages divider staying at the room-open position instead of re-anchoring at the last read when the window loses focus. diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 6a48ff989..d44751aae 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -830,9 +830,17 @@ export function RoomTimeline({ useDocumentFocusChange( useCallback( (inFocus) => { - if (inFocus && atBottomState) tryAutoMarkAsRead(); + if (inFocus) { + if (atBottomState) tryAutoMarkAsRead(); + return; + } + // Re-anchor the divider at the last read when tabbing out while caught up. + if (atBottomState && timelineSync.liveTimelineLinked) { + readUptoEventIdRef.current = undefined; + setUnreadInfo(undefined); + } }, - [tryAutoMarkAsRead, atBottomState] + [tryAutoMarkAsRead, atBottomState, timelineSync.liveTimelineLinked, setUnreadInfo] ) );