From 37dbf1f9bb04d23e2407c8d856d3b458ae1f349e Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sat, 31 Oct 2026 10:04:56 +0530 Subject: [PATCH] prevent scroll top cache when timeline is loading --- src/app/features/room/hooks/useTimeline.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/features/room/hooks/useTimeline.ts b/src/app/features/room/hooks/useTimeline.ts index 11a932e06..c3c08ccad 100644 --- a/src/app/features/room/hooks/useTimeline.ts +++ b/src/app/features/room/hooks/useTimeline.ts @@ -144,12 +144,15 @@ export const useTimelineScrollRestore = ( const batch = timeline.batch.read; if (typeof scrollTop === 'number') { scrollEl.scrollTo({ top: scrollTop, behavior: 'instant' }); - } else if (batch.next.end && batch.messages.events.length > 0) { + } else if (batch.next.end && batch.size > 0) { scrollToBottom(scrollEl, 'instant'); } } return () => { if (!scrollEl) return; + const batch = timeline.batch.read; + // do not set cache if event are not loaded yet. + if (batch.size === 0) return; // eslint-disable-next-line no-param-reassign timeline.range.scrollTopCache = scrollEl.scrollTop; };