Skip to content

Commit 81525b6

Browse files
fix: resolve scroll indicator race condition (#1225)
Use wasAtBottomRef.current (continuously updated by scroll handler) as the primary check in the MutationObserver callback, falling back to the prevScrollHeight computation. This prevents the indicator from briefly appearing when a programmatic scroll and DOM mutation race — the scroll handler may have already registered "at bottom" even if prevScrollHeight is stale. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b533587 commit 81525b6

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

client/src/components/scroll/useScrollAwareness.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ export function useScrollAwareness(containerRef, options = {}) {
7777
return;
7878
}
7979

80-
// Check if user WAS at bottom BEFORE content was added
81-
// We use prevScrollHeight because that's the height when user last scrolled
82-
const wasAtBottom = isAtBottom(
80+
// Check if user was at bottom before content was added.
81+
// Prefer the ref (continuously updated by scroll handler) over
82+
// recomputing from the cached prevScrollHeight, which can be
83+
// stale when a programmatic scroll and DOM mutation race.
84+
const wasAtBottom = wasAtBottomRef.current || isAtBottom(
8385
prevScrollHeight,
8486
scrollTop,
8587
container.clientHeight,

0 commit comments

Comments
 (0)