diff --git a/.changeset/a_fix_scroll_behaviour.md b/.changeset/a_fix_scroll_behaviour.md new file mode 100644 index 00000000..b652cb64 --- /dev/null +++ b/.changeset/a_fix_scroll_behaviour.md @@ -0,0 +1,5 @@ +--- +sable: patch +--- + +Fix scroll clamping to bottom while scrolling up. diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 51e155a5..c6736e27 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -103,7 +103,6 @@ import { useIntersectionObserver, } from '$hooks/useIntersectionObserver'; import { markAsRead } from '$utils/notifications'; -import { useDebounce } from '$hooks/useDebounce'; import { getResizeObserverEntry, useResizeObserver } from '$hooks/useResizeObserver'; import { inSameDay, minuteDifference, timeDayMonthYear, today, yesterday } from '$utils/time'; import { createMentionElement, isEmptyEditor, moveCursor } from '$components/editor'; @@ -917,33 +916,26 @@ export function RoomTimeline({ } }, [mx, room, hideReads]); - const debounceSetAtBottom = useDebounce( - useCallback( - (entry: IntersectionObserverEntry) => { - if (!entry.isIntersecting) setAtBottom(false); - }, - [setAtBottom] - ), - { wait: 1000 } - ); - useIntersectionObserver( useCallback( (entries) => { const target = atBottomAnchorRef.current; if (!target) return; const targetEntry = getIntersectionObserverEntry(target, entries); - if (targetEntry) debounceSetAtBottom(targetEntry); - if (targetEntry?.isIntersecting) { - // Track scroll position independently of atLiveEndRef so that atBottom - // is always accurate. tryAutoMarkAsRead still requires atLiveEndRef. + if (!targetEntry) return; + + if (targetEntry.isIntersecting) { + // User has reached the bottom setAtBottom(true); if (atLiveEndRef.current && document.hasFocus()) { tryAutoMarkAsRead(); } + } else { + // User has intentionally scrolled up. + setAtBottom(false); } }, - [debounceSetAtBottom, tryAutoMarkAsRead, setAtBottom] + [tryAutoMarkAsRead, setAtBottom] ), useCallback( () => ({