Skip to content

timeline: fix auto-scroll undershooting on tall messages#2661

Open
amaanq wants to merge 1 commit intocinnyapp:devfrom
amaanq:fix/auto-scroll-undershoots-tall-messages
Open

timeline: fix auto-scroll undershooting on tall messages#2661
amaanq wants to merge 1 commit intocinnyapp:devfrom
amaanq:fix/auto-scroll-undershoots-tall-messages

Conversation

@amaanq
Copy link

@amaanq amaanq commented Feb 18, 2026

Description

When a tall message (a sticker, a long text block) arrives in an active
room, useLiveEventArrive fires and triggers scrollToBottom(scrollEl, 'smooth') from a layout effect. But reactions and read receipts from
other participants fire the same handler milliseconds later, and each
scrollTo({behavior: 'smooth'}) call cancels the inflight CSS
animation and restarts from wherever the viewport has reached, usually
only a few pixels further. The scroll never converges, leaving the new
message partially off-screen.

This commit replaces the native smooth scroll with a
requestAnimationFrame loop that reads scrollHeight - offsetHeight
each frame and advances scrollTop by 20% of the remaining distance
(~230 ms to 95% at 60 fps). Subsequent live events are no-ops because
the running loop already chases the live bottom. wheel and
touchstart listeners cancel the animation so back-scrolling is
unaffected, and cancelSmoothScroll clears state for instant scrolls
on room switches.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@github-actions
Copy link

github-actions bot commented Feb 18, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@amaanq
Copy link
Author

amaanq commented Feb 18, 2026

I have read the CLA Document and I hereby sign the CLA

ajbura added a commit to cinnyapp/cla that referenced this pull request Feb 18, 2026
@amaanq amaanq force-pushed the fix/auto-scroll-undershoots-tall-messages branch 2 times, most recently from fdd8af4 to c862128 Compare February 18, 2026 16:29
@amaanq amaanq marked this pull request as draft February 18, 2026 16:55
@amaanq amaanq force-pushed the fix/auto-scroll-undershoots-tall-messages branch from c862128 to 9561851 Compare February 18, 2026 18:05
@amaanq amaanq changed the title fix: auto scroll undershoots on tall messages and stickers timeline: fix auto-scroll undershooting on tall messages Feb 18, 2026
@amaanq amaanq marked this pull request as ready for review February 18, 2026 18:06
@amaanq amaanq force-pushed the fix/auto-scroll-undershoots-tall-messages branch from 9561851 to ce87b46 Compare February 18, 2026 18:15
When a tall message (a sticker, a long text block) arrives in an active
room, `useLiveEventArrive` fires and triggers `scrollToBottom(scrollEl,
'smooth')` from a layout effect. But reactions and read receipts from
other participants fire the same handler milliseconds later, and each
`scrollTo({behavior: 'smooth'})` call cancels the inflight CSS
animation and restarts from wherever the viewport has reached, usually
only a few pixels further. The scroll never converges, leaving the new
message partially off-screen.

This commit replaces the native smooth scroll with a
`requestAnimationFrame` loop that reads `scrollHeight - offsetHeight`
each frame and advances `scrollTop` by 20% of the remaining distance
(~230 ms to 95% at 60 fps). Subsequent live events are no-ops because
the running loop already chases the live bottom. `wheel` and
`touchstart` listeners cancel the animation so back-scrolling is
unaffected, and `cancelSmoothScroll` clears state for instant scrolls
on room switches.

Fixes cinnyapp#2259.
@amaanq amaanq force-pushed the fix/auto-scroll-undershoots-tall-messages branch from ce87b46 to 4d08f47 Compare February 18, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cinny does not scroll to the bottom on receiving a new message.

1 participant