From dfdcf3301675b3fa3bb393e132b342feca6ccb3c Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sun, 26 Jul 2026 16:46:46 +0200 Subject: [PATCH] fix(timeline): keep following the bottom when rows grow after rendering --- .changeset/fix-timeline-late-growth-scroll.md | 5 +++++ src/app/features/room/RoomTimeline.tsx | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .changeset/fix-timeline-late-growth-scroll.md diff --git a/.changeset/fix-timeline-late-growth-scroll.md b/.changeset/fix-timeline-late-growth-scroll.md new file mode 100644 index 000000000..b8a0042a7 --- /dev/null +++ b/.changeset/fix-timeline-late-growth-scroll.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Keep following the timeline when a message grows after it renders diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 66122468e..019d20784 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -769,6 +769,22 @@ export function RoomTimeline({ return () => observer.disconnect(); }, [syncAtBottom]); + // Decrypting rows and late-loading images grow without changing eventsLength, + // so useTimelineSync's auto-scroll never re-fires for them. + const lastScrollSizeRef = useRef(0); + useLayoutEffect(() => { + const v = vListRef.current; + if (!v) return; + + const grew = v.scrollSize > lastScrollSizeRef.current; + lastScrollSizeRef.current = v.scrollSize; + + if (!grew || !atBottomRef.current || !liveTimelineLinkedRef.current) return; + + const lastIndex = processedEventsRef.current.length - 1; + if (lastIndex >= 0) v.scrollToIndex(lastIndex, { align: 'end' }); + }); + const actions = useTimelineActions({ room, mx, @@ -1048,6 +1064,7 @@ export function RoomTimeline({ useEffect(() => { viewportFillCountRef.current = 0; + lastScrollSizeRef.current = 0; }, [room.roomId]); // Re-enters on every length change, so an unfillable viewport pages to the start of the