Skip to content

fix(chat): align scrollbar/keyboard detach with wheel/touch re-engage threshold#5094

Open
waleedlatif1 wants to merge 1 commit into
stagingfrom
autoscroll-reengage-threshold
Open

fix(chat): align scrollbar/keyboard detach with wheel/touch re-engage threshold#5094
waleedlatif1 wants to merge 1 commit into
stagingfrom
autoscroll-reengage-threshold

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Type of Change

  • Bug fix

Testing

Verified in headless Chromium against the exact onScroll logic: after a scrollbar-drag detach, a re-pin landing 20px from the bottom (within 30px, outside 5px) no longer re-engages (it did before this change); genuine return to within 5px still re-engages. tsc clean, biome clean.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

… threshold

The onScroll detach branch set only stickyRef.current = false, leaving
userDetachedRef false, so a scrollbar-drag or keyboard detach kept the lenient
30px (STICK_THRESHOLD) re-engage threshold instead of the strict 5px
(REATTACH_THRESHOLD) used after wheel/touch. A programmatic virtualizer re-pin
landing within 30px could then snap autoscroll back on right after the user
deliberately scrolled away. Reuse the detach() helper so all detach paths set
userDetachedRef consistently.
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 16, 2026 6:39am

Request Review

@cursor

cursor Bot commented Jun 16, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Single-line behavior fix in chat auto-scroll detach logic; no auth, data, or API surface changes.

Overview
Fixes inconsistent auto-scroll detach behavior in use-auto-scroll when the user scrolls up via the scrollbar or keyboard.

The onScroll detach branch previously only cleared stickyRef, leaving userDetachedRef false. That meant re-attach still used the lenient 30px STICK_THRESHOLD instead of the strict 5px REATTACH_THRESHOLD used after wheel/touch detaches. A programmatic virtualizer re-pin within 30px of the bottom could wrongly turn auto-scroll back on after the user had intentionally scrolled away.

The branch now calls the shared detach() helper (same as wheel/touch), so both refs update and detached users must return within 5px to re-engage.

Reviewed by Cursor Bugbot for commit caf77ad. Configure here.

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This is a one-line follow-up bug fix to PR #5093. The onScroll detach branch (which handles scrollbar-drag and keyboard-initiated upward scrolls) was calling stickyRef.current = false directly instead of the shared detach() helper, leaving userDetachedRef.current as false. This caused subsequent re-engagement checks to use the lenient STICK_THRESHOLD (30 px) instead of the stricter REATTACH_THRESHOLD (5 px), which could let a react-virtual programmatic re-pin within 30 px silently snap auto-scroll back on after a deliberate user scroll-away.

  • Fix: replaces the bare stickyRef.current = false in the onScroll else-if branch with the existing detach() call, which also sets userDetachedRef.current = true, making all four detach paths (wheel, touch, scrollbar drag, keyboard) consistent.
  • Scope: single line, no new API surface, no behavioral change for wheel/touch detaches (they already called detach() directly).

Confidence Score: 5/5

Safe to merge — the change is a one-line correction to a clearly identified inconsistency between detach paths.

The only code touched is the else-if branch inside onScroll that was the sole remaining caller not using the shared detach() helper. All four detach paths now set both refs identically. The fix introduces no new logic and cannot regress wheel or touch detaches, which already went through detach(). The re-engagement condition is unchanged; only the threshold used after a scrollbar/keyboard detach tightens from 30px to 5px, which is the intended behavior documented throughout the hook.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/hooks/use-auto-scroll.ts Single-line fix: replaces bare stickyRef.current = false with detach() in the onScroll upward-scroll branch, ensuring userDetachedRef is set on all detach paths so the strict REATTACH_THRESHOLD is honored after scrollbar/keyboard detaches.

Reviews (1): Last reviewed commit: "fix(chat): align scrollbar/keyboard deta..." | Re-trigger Greptile

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.

1 participant