You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] jumpToBottom does not cancel the in-flight spring, so animation loops stack #5663
jumpToBottom is documented as cancelling any in-flight spring so a later tick cannot fight the assignment, but it only clears animatingRef. animate() never reads animatingRef — it continues while lockedRef is true and the content is scrollable — and scrollToBottom sets lockedRef = true immediately before calling jumpToBottom. The running loop therefore survives while animatingRef reads false, so the next startAnimation starts a second loop alongside it.
Two consequences: per-frame scroll distance multiplies with the number of live loops, and animatingRef no longer reflects reality, which disables the wheel and touch interrupts even in the animated path.
Expected: after jumpToBottom, exactly zero or one animation loop is live.
Reproduction
Mount useChatStreamScroll on a scrollable container, locked.
Grow the content so scrollIfLocked starts a spring.
Call scrollToBottom({ behavior: 'instant' }) while that spring is running.
Grow the content again to trigger startAnimation.
Observed: two requestAnimationFrame chains are live; a single frame advances scrollTop by roughly twice what one loop advances it (~240px against ~120px at the default damping: 0.7 / stiffness: 0.05 / mass: 1.25). Each further repetition adds another loop.
A generation token incremented by jumpToBottom and checked at the top of animate() would make the documented cancel real.
Electron 40 (Chromium 142), macOS 15. Found while adopting the hook in Apache Maka; not patched locally — after the fixes on our side the path that reaches it is narrow, so we are only reporting it.
Confirmed, and this one is mine — jumpToBottom came in with #3800.
The invariant it breaks: animatingRef carries two meanings, "a rAF loop is live" and "we are following". Before #3800 every site that cleared it also cleared lockedRef (unlock, the scroll-up branch, the wheel and touch handlers), so a live loop always died on its next tick at !lockedRef.current. jumpToBottom is the first site that clears the flag while lockedRef stays true — and scrollToBottom sets lockedRef = true immediately before calling it, so the loop's own exit cannot fire. Everything you describe follows from that.
One correction on the magnitude: the loops share lastTickRef, so the second callback in a frame reads tickDelta ≈ 0 and contributes almost no displacement. What doubles is the number of velocity updates per frame, and simulating that recurrence at the default constants gives roughly 1.1–1.2x peak per-frame advance rather than 2x. The stale loop also settles itself on its next tick — diff and velocity are both zero right after the jump — unless content grows inside that one-frame window, which is what steps 3-4 race and why the path is as narrow as you found it.
The stale animatingRef half is the one with teeth, and it compounds with #5662: while a zombie loop is live the wheel and touch releases are dead exactly when onScroll's direction check is also blind, since growth changes the geometry on nearly every event.
I will fix both in one PR: a generation token that jumpToBottom and startAnimation bump and animate() checks, plus taking the gesture handlers off animatingRef entirely (see #5662). With the gates no longer reading it, animatingRef goes back to being pure loop bookkeeping.
Activity
yyq1025 commentedon Aug 29, 2026
Confirmed, and this one is mine —
jumpToBottomcame in with #3800.The invariant it breaks:
animatingRefcarries two meanings, "a rAF loop is live" and "we are following". Before #3800 every site that cleared it also clearedlockedRef(unlock, the scroll-up branch, the wheel and touch handlers), so a live loop always died on its next tick at!lockedRef.current.jumpToBottomis the first site that clears the flag whilelockedRefstays true — andscrollToBottomsetslockedRef = trueimmediately before calling it, so the loop's own exit cannot fire. Everything you describe follows from that.One correction on the magnitude: the loops share
lastTickRef, so the second callback in a frame readstickDelta ≈ 0and contributes almost no displacement. What doubles is the number of velocity updates per frame, and simulating that recurrence at the default constants gives roughly 1.1–1.2x peak per-frame advance rather than 2x. The stale loop also settles itself on its next tick —diffand velocity are both zero right after the jump — unless content grows inside that one-frame window, which is what steps 3-4 race and why the path is as narrow as you found it.The stale
animatingRefhalf is the one with teeth, and it compounds with #5662: while a zombie loop is live the wheel and touch releases are dead exactly whenonScroll's direction check is also blind, since growth changes the geometry on nearly every event.I will fix both in one PR: a generation token that
jumpToBottomandstartAnimationbump andanimate()checks, plus taking the gesture handlers offanimatingRefentirely (see #5662). With the gates no longer reading it,animatingRefgoes back to being pure loop bookkeeping.fix(chat): only the reader can release auto-follow (#5662, #5663) (#5678