From 9beff5d4fb0bee4b2bee5f1c973281d16603f3ab Mon Sep 17 00:00:00 2001 From: 7w1 Date: Wed, 11 Mar 2026 02:35:08 -0500 Subject: [PATCH] plz work part 3 electric boogalee --- src/app/features/room/RoomTimeline.tsx | 57 +++++++++----------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 2d680610..5d713600 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -2185,18 +2185,18 @@ export function RoomTimeline({ } else { backPaginationJSX = (
- {backwardStatus === 'loading' && ( - - - - )} -
+ /> + ); + const backwardLoadingJSX = backwardStatus === 'loading' && ( + + + ); } } @@ -2270,45 +2270,26 @@ export function RoomTimeline({ ); } } - - const prevBackwardStatus = useRef(backwardStatus); - const scrollAnchor = useRef<{ id: string; offsetTop: number } | null>(null); + const lastScrollHeight = useRef(0); useLayoutEffect(() => { const scrollEl = scrollRef.current; if (!scrollEl) return; - // When going to loading store the exact position - if (prevBackwardStatus.current === 'idle' && backwardStatus === 'loading') { - const topMessage = scrollEl.querySelector('[data-message-id]'); - if (topMessage) { - scrollAnchor.current = { - id: topMessage.getAttribute('data-message-id') || '', - offsetTop: (topMessage as HTMLElement).offsetTop, - }; - } + if (backwardStatus === 'loading') { + lastScrollHeight.current = scrollEl.scrollHeight; } - // After fetch finishes calculate new content and force scroll to position hopefully - if (prevBackwardStatus.current === 'loading' && backwardStatus === 'idle') { - if (scrollAnchor.current) { - const anchorNode = scrollEl.querySelector( - `[data-message-id="${scrollAnchor.current.id}"]` - ) as HTMLElement; + if (backwardStatus === 'idle' && lastScrollHeight.current > 0) { + const newScrollHeight = scrollEl.scrollHeight; + const heightDifference = newScrollHeight - lastScrollHeight.current; - if (anchorNode) { - const delta = anchorNode.offsetTop - scrollAnchor.current.offsetTop; - - if (delta > 0) { - scrollEl.scrollBy({ top: delta, behavior: 'instant' }); - } - } - scrollAnchor.current = null; + if (heightDifference > 0) { + scrollEl.scrollTop += heightDifference; } + lastScrollHeight.current = 0; } - - prevBackwardStatus.current = backwardStatus; - }, [backwardStatus, processedEvents]); + }, [backwardStatus, processedEvents.length]); return (