Skip to content
Source
Sign inSign up
pingdotgg/t3code

Tighten chat auto-tail to true bottom position #81

Closedjuliusmarmingewants to merge 4 commits intomain fromcodething/b1c10980opened View on GitHub

juliusmarmingecommented

Summary

  • Replace isScrollContainerNearBottom with isScrollContainerAtBottom to require true bottom alignment semantics.
  • Reduce auto-tail tolerance from 64px to a 2px epsilon and clamp overscroll distance to 0.
  • Update ChatView scrolling behavior to auto-tail only while the user is at bottom, using layout-timed updates tied to message/worklog changes.
  • Refresh chat scroll unit tests to match new naming/behavior, including overscroll and epsilon edge cases.

Testing

  • Updated unit tests in apps/web/src/chat-scroll.test.ts cover: exact bottom, within epsilon, above epsilon, negative epsilon clamp, non-finite fallback, and overscroll handling.
  • Not run: pnpm --filter web test
  • Not run: project lint scripts

Open with Devin

Note

Medium Risk Behavioral change in the core chat scrolling UX; risk is mainly regressions across input types (wheel/touch/pointer) and timing-related auto-scroll edge cases.

Overview Chat auto-tail is tightened from a “near bottom” threshold to a true-bottom check via isScrollContainerAtBottom, reducing tolerance to a 2px epsilon and clamping overscroll distance to 0.

ChatView now tails using a requestAnimationFrame-debounced layout effect tied to message/worklog changes, and disables auto-tail when wheel/touch/pointer input indicates the user is scrolling up (re-enabling when returning to bottom). Tests are updated/renamed to cover epsilon edge cases and overscroll behavior.

Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3031dfd122686f67e34fa6a2b9ce69b3eee6ccdc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).

Summary by CodeRabbit

  • Bug Fixes

    • Improved auto-scroll detection with finer bottom sensitivity; overscrolled positions are treated as at-bottom and non-finite values handled correctly.
  • New Features

    • Staged "auto-tail" auto-scroll using requestAnimationFrame to debounce scrolling.
    • Auto-scroll now respects user intent across wheel/pointer/touch (disabled when user scrolls up) and pending auto-scrolls are cancelled on unmount.
    1. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Tighten chat auto-tail by using a 2px epsilon and update ChatView to auto-scroll only when at true bottom in chat-scroll.ts and ChatView.tsx

      Rename AUTO_SCROLL_BOTTOM_THRESHOLD_PX to AUTO_SCROLL_BOTTOM_EPSILON_PX set to 2, replace isScrollContainerNearBottom with isScrollContainerAtBottom, and rework ChatView auto-tail to honor bottom state and user scroll intent with requestAnimationFrame-based tailing.

      📍Where to Start

      Start with isScrollContainerAtBottom and AUTO_SCROLL_BOTTOM_EPSILON_PX in chat-scroll.ts, then review onMessagesScroll and related handlers in ChatView.tsx.


      Macroscope summarized 3031dfd.
    2. greptile-apps[bot](GitHub profile, opens in a new tab)commented

      Greptile Summary

      This PR tightens chat auto-scroll behavior from a "near bottom" 64px threshold to a strict "at bottom" 2px epsilon, and refactors ChatView to use requestAnimationFrame-debounced scrolling that only tails while the user stays at the bottom.

      Key Changes:

      • Renamed isScrollContainerNearBottom → isScrollContainerAtBottom with proper overscroll clamping
      • Reduced tolerance from 64px to 2px for stricter bottom detection
      • Added requestAnimationFrame debouncing to prevent redundant scroll operations
      • Introduced wheel event handler and scroll position tracking to detect user intent

      Critical Issues Found:

      • scrollContainer.scrollTop is read immediately after async scrollTo(), capturing stale values instead of final scroll position (line 1107-1108)
      • Smooth scrolling removed - now uses instant "auto" behavior during streaming, causing jarring jumps (line 1116)
      • Wheel handler disables tailing on any upward scroll, even accidental trackpad touches while at bottom (line 1141-1144)

      Confidence Score: 1/5

      • This PR has critical logic bugs that will break auto-scroll UX during streaming
      • Three critical bugs found: (1) reading stale scroll position after async scrollTo causes incorrect state tracking, (2) removal of smooth scrolling creates jarring UX, (3) overly aggressive wheel handler breaks tailing on accidental input. The utility functions are correct, but ChatView integration has fundamental issues.
      • apps/web/src/components/ChatView.tsx requires immediate fixes to scrolling logic (lines 1107-1108, 1116, 1141-1144)

      Important Files Changed

      FilenameOverview
      apps/web/src/chat-scroll.tsRenamed function to isScrollContainerAtBottom with tighter 2px epsilon and proper overscroll handling via Math.max(0, ...) clamp - implementation is correct
      apps/web/src/chat-scroll.test.tsUpdated tests match new 2px epsilon semantics and added overscroll coverage - all test logic is correct
      apps/web/src/components/ChatView.tsxMajor auto-scroll refactor with three critical bugs: reads stale scrollTop after async scrollTo(), removes smooth scrolling behavior, and overly aggressive wheel-based disengage

      Flowchart

      %%{init: {'theme': 'neutral'}}%%
      flowchart TD
          A[Message/WorkLog Change] --> B{shouldAutoScrollRef.current?}
          B -->|No| Z[No Action]
          B -->|Yes| C[requestAutoTailToBottom]
          C --> D{Pending Frame?}
          D -->|Yes| Z
          D -->|No| E[Schedule RAF]
          E --> F[RAF Callback]
          F --> G{Still shouldAutoScroll?}
          G -->|No| Z
          G -->|Yes| H[scrollMessagesToBottom]
          H --> I[scrollTo top: scrollHeight]
          I --> J[Read scrollTop - STALE!]
          J --> K[Update lastKnown refs]
          
          L[User Scrolls] --> M[onMessagesScroll]
          M --> N{isScrollContainerAtBottom?}
          N -->|Yes| O[Enable auto-scroll]
          N -->|No| P{Currently tailing?}
          P -->|No| Z
          P -->|Yes| Q{Scrolled up AND no height change?}
          Q -->|Yes| R[Disable auto-scroll]
          Q -->|No| S[Keep tailing]
          
          T[Wheel Event] --> U{deltaY < 0?}
          U -->|Yes upward| V[Disable auto-scroll]
          U -->|No| Z
      Last reviewed commit: 0cb4e75
    3. 3 files reviewed, 1 comment [Edit Code Review Agent Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews)
      apps/web/src/components/ChatView.tsx lines 1114 to 1117OutdatedResolvedby juliusmarminge
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      No actionable comments were generated in the recent review. 🎉


      Walkthrough

      Renames auto-scroll API from "threshold" to "epsilon" (default 64 → 2), updates function/constant names, clamps distanceFromBottom calculation, and adds requestAnimationFrame-based debounced auto-tail logic and user-input handlers in ChatView to gate automatic bottom-scrolling.

      Changes

      Cohort / File(s)Summary
      Core scroll detection module
      apps/web/src/chat-scroll.ts
      Renamed AUTO_SCROLL_BOTTOM_THRESHOLD_PX → AUTO_SCROLL_BOTTOM_EPSILON_PX (default 64 → 2). Renamed isScrollContainerNearBottom → isScrollContainerAtBottom; parameter thresholdPx → epsilonPx. Clamped distanceFromBottom with Math.max(0, ...) and compare against epsilon.
      Test suite
      apps/web/src/chat-scroll.test.ts
      Updated imports and assertions to use AUTO_SCROLL_BOTTOM_EPSILON_PX and isScrollContainerAtBottom. Adjusted test scrollTop values and added/updated cases for non-finite and overscroll behavior (e.g., 599, 610) to reflect epsilon semantics.
      Chat component
      apps/web/src/components/ChatView.tsx
      Replaced isScrollContainerNearBottom with isScrollContainerAtBottom. Added refs (lastKnownScrollTopRef, lastKnownScrollHeightRef, pendingAutoScrollFrameRef, etc.), input handlers (onMessagesWheel, pointer/touch handlers), and requestAutoTailToBottom to schedule guarded auto-scroll via requestAnimationFrame. Cleans up RAF on unmount and adjusts auto-tail triggers.

      Sequence Diagram(s)

      mermaid sequenceDiagram participant User participant ChatView participant ScrollContainer participant RAF as requestAnimationFrame User->>ScrollContainer: scroll / wheel / touch input ScrollContainer->>ChatView: onMessagesScroll / onMessagesWheel / onMessagesTouch* ChatView-->>ChatView: update lastKnownScrollTopRef/flags; call isScrollContainerAtBottom alt user scrolled upward or pointer active ChatView-->>ChatView: disable/stall auto-scroll (clear pending RAF) else messages changed or auto-tail desired ChatView->>RAF: requestAutoTailToBottom (schedule frame) RAF-->>ChatView: frame callback ChatView->>ScrollContainer: scrollMessagesToBottom() end

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      🚥 Pre-merge checks | ✅ 2 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (2 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe pull request title 'Tighten chat auto-tail to true bottom position' directly and clearly summarizes the main change: refactoring the scroll detection logic to enforce stricter bottom alignment by reducing the tolerance from 64px to 2px epsilon and renaming related APIs to reflect this stricter 'at bottom' semantics.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      • 📝 Generate docstrings
        🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment
      • Commit unit tests in branch `codething/b1c10980`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    5. @greptileai review

    6. Actionable comments posted: 1

      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Inline comments:
      In `@apps/web/src/components/ChatView.tsx`:
      - Around line 1122-1145: The auto-tail logic in ChatView (inside the effect that
      uses isScrollContainerAtBottom and refs like shouldAutoScrollRef,
      lastKnownScrollTopRef, lastKnownScrollHeightRef) can fail to relinquish control
      for user-initiated drag/touch/keyboard scrolling because contentHeightChanged
      masks upward user scrolls; update the logic to treat only user-initiated events
      as intent by checking event.isTrusted where applicable and by adding/using an
      onScroll handler that inspects the native ScrollEvent.isTrusted (and/or updating
      onMessagesWheel to check event.isTrusted) so that when the user scrolls up
      (scrolledUp detected) and the event is trusted you set
      shouldAutoScrollRef.current = false regardless of contentHeightChanged; ensure
      isScrollContainerAtBottom behavior is unchanged for programmatic scrolls.
      @@ -1110 +1125,21 @@
      1125+
      1126+ if (atBottom) {
      1127+ shouldAutoScrollRef.current = true;
      1128+ } else if (shouldAutoScrollRef.current) {
      1129+ // While tailing, only relinquish control when the user scrolls upward.
      1130+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
      1131+ const contentHeightChanged =
      1132+ Math.abs(currentScrollHeight - lastKnownScrollHeightRef.current) > 1;
      1133+ if (scrolledUp && !contentHeightChanged) {
      1134+ shouldAutoScrollRef.current = false;
      1135+ }
      1136+ }
      1137+
      1138+ lastKnownScrollTopRef.current = currentScrollTop;
      1139+ lastKnownScrollHeightRef.current = currentScrollHeight;
      1140+ }, []);
      1141+ const onMessagesWheel = useCallback((event: WheelEvent<HTMLDivElement>) => {
      1142+ if (event.deltaY < 0) {
      1143+ shouldAutoScrollRef.current = false;
      1144+ }
      11101145 }, []);
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟡 Minor

      🧩 Analysis chain

      🏁 Script executed:

      # First, check the React version in the project
      find . -name "package.json" -type f | head -5 | xargs grep -l '"react"' | head -1 | xargs cat | grep -A 2 '"react"'

      Repository: pingdotgg/codething-mvp

      Length of output: 151


      🌐 Web query:

      React 19 UIEvent isTrusted property scroll events TypeScript

      💡 Result:

      • What isTrusted means: event.isTrusted is true for events generated by the browser/UA, and false for events created and dispatched via dispatchEvent() (with some caveats like click). [1]
      • For scroll, it’s not a reliable “user scrolled” detector: programmatic scrolling (e.g., window.scrollTo, setting scrollTop) can still produce scroll events where isTrusted is true, so it won’t consistently tell you whether the user vs code caused the scroll. [2]

      React 19 + TypeScript: how to type onScroll so isTrusted is available

      Use React’s event type (not the DOM UIEvent type alias you might import/use accidentally):

      function onScroll(e: React.UIEvent<HTMLDivElement>) {
        const trusted1 = e.isTrusted;            // available on React SyntheticEvent
        const trusted2 = e.nativeEvent.isTrusted; // available on the native event too
      }

      React’s UIEvent type includes isTrusted (via SyntheticEvent). [3]

      If TypeScript still says isTrusted doesn’t exist, it’s usually a version mismatch (older @types/react / TS DOM libs). Align/upgrade react + @types/react + typescript so the SyntheticEvent/DOM Event definitions include isTrusted. [1] [3]

      Sources: MDN on Event.isTrusted [1]; discussion of scroll + isTrusted behavior [2]; React TypeScript UIEvent including isTrusted [3].

      [1] (developer.mozilla.org) [2] (stackoverflow.com) [3] (use-form.netlify.app)

      Citations:


      🏁 Script executed:

      # Verify the file exists and check imports
      cat -n apps/web/src/components/ChatView.tsx | head -50

      Repository: pingdotgg/codething-mvp

      Length of output: 1873


      🏁 Script executed:

      # Search for scrollTop assignments and scrolling logic in ChatView.tsx
      rg "scrollTop|scrollTo|shouldAutoScrollRef" apps/web/src/components/ChatView.tsx -A 3 -B 1

      Repository: pingdotgg/codething-mvp

      Length of output: 1844


      🏁 Script executed:

      # Look for auto-scroll logic more broadly
      rg -i "autoscroll|auto-scroll|shouldAutoScroll" apps/web/src/components/ChatView.tsx -B 2 -A 5

      Repository: pingdotgg/codething-mvp

      Length of output: 2660


      Auto-tail may not release on touch/scrollbar drag during streaming.

      contentHeightChanged suppresses disabling tail mode even when the user scrolls up via drag/touch/keyboard while new messages arrive. Since programmatic scrolls in this code always move downward, checking scrolledUp implicitly filters for user scrolls, making event.isTrusted a reliable indicator of user intent in this context.

      💡 Suggested adjustment
      -  const onMessagesScroll = useCallback(() => {
      +  const onMessagesScroll = useCallback((event: UIEvent<HTMLDivElement>) => {
           const scrollContainer = messagesScrollRef.current;
           if (!scrollContainer) return;
           const currentScrollTop = scrollContainer.scrollTop;
           const currentScrollHeight = scrollContainer.scrollHeight;
           const atBottom = isScrollContainerAtBottom(scrollContainer);
      
           if (atBottom) {
             shouldAutoScrollRef.current = true;
           } else if (shouldAutoScrollRef.current) {
             // While tailing, only relinquish control when the user scrolls upward.
             const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
             const contentHeightChanged =
               Math.abs(currentScrollHeight - lastKnownScrollHeightRef.current) > 1;
      -      if (scrolledUp && !contentHeightChanged) {
      +      const userInitiated = event.isTrusted;
      +      if (scrolledUp && (userInitiated || !contentHeightChanged)) {
               shouldAutoScrollRef.current = false;
             }
           }
      
           lastKnownScrollTopRef.current = currentScrollTop;
           lastKnownScrollHeightRef.current = currentScrollHeight;
         }, []);
       import {
         type ClipboardEvent,
         type DragEvent,
         type FormEvent,
         type KeyboardEvent,
      +  type UIEvent,
         type WheelEvent,
         memo,
      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@apps/web/src/components/ChatView.tsx` around lines 1122 - 1145, The auto-tail
      logic in ChatView (inside the effect that uses isScrollContainerAtBottom and
      refs like shouldAutoScrollRef, lastKnownScrollTopRef, lastKnownScrollHeightRef)
      can fail to relinquish control for user-initiated drag/touch/keyboard scrolling
      because contentHeightChanged masks upward user scrolls; update the logic to
      treat only user-initiated events as intent by checking event.isTrusted where
      applicable and by adding/using an onScroll handler that inspects the native
      ScrollEvent.isTrusted (and/or updating onMessagesWheel to check event.isTrusted)
      so that when the user scrolls up (scrolledUp detected) and the event is trusted
      you set shouldAutoScrollRef.current = false regardless of contentHeightChanged;
      ensure isScrollContainerAtBottom behavior is unchanged for programmatic scrolls.
    7. cursor[bot](GitHub profile, opens in a new tab)commented

      Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

      • ✅ Fixed: Wheel handler breaks auto-scroll on non-scrollable containers
        • Added a guard to only disable auto-scroll on upward wheel events when the scroll container actually has overflow (scrollHeight > clientHeight), preventing permanent auto-scroll loss on non-scrollable containers.

      Create PR

      Or push these changes by commenting:

      @cursor push 082ec99238
      Preview (pingdotgg/codething-mvp@082ec99238)
      diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
      --- a/apps/web/src/components/ChatView.tsx
      +++ b/apps/web/src/components/ChatView.tsx
      @@ -1140,7 +1140,10 @@
         }, []);
         const onMessagesWheel = useCallback((event: WheelEvent<HTMLDivElement>) => {
           if (event.deltaY < 0) {
      -      shouldAutoScrollRef.current = false;
      +      const el = messagesScrollRef.current;
      +      if (el && el.scrollHeight > el.clientHeight) {
      +        shouldAutoScrollRef.current = false;
      +      }
           }
         }, []);
         useLayoutEffect(() => {
    8. 3 files reviewed, 3 comments [Edit Code Review Agent Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews)
      @@ -1094,10 +1098,11 @@
      10941098 }
      10951099 }, [lastInvokedScriptByProjectId]);
      10961100
      1097- // Auto-scroll on new messages
      1098- const messageCount = activeThread?.messages.length ?? 0;
      1101+ // Auto-tail while the user stays at the bottom.
      10991102 const workLogCount = workLogEntries.length;
      11001103 const scrollMessagesToBottom = useCallback((behavior: ScrollBehavior = "auto") => {
      11011104 const scrollContainer = messagesScrollRef.current;
      11021105 if (!scrollContainer) return;
      11031106 scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior });
      1107+ lastKnownScrollTopRef.current = scrollContainer.scrollTop;
      1108+ lastKnownScrollHeightRef.current = scrollContainer.scrollHeight;
      greptile-apps[bot](GitHub profile, opens in a new tab)commented

      scrollContainer.scrollTop read immediately after scrollTo() may not reflect the final scroll position yet (scrolling is async). This will capture stale/intermediate values rather than the actual bottom position, causing incorrect tail-disengage logic in onMessagesScroll.

      @@ -1094,12 +1098,19 @@
      10941098 }
      10951099 }, [lastInvokedScriptByProjectId]);
      10961100
      1097- // Auto-scroll on new messages
      1098- const messageCount = activeThread?.messages.length ?? 0;
      1101+ // Auto-tail while the user stays at the bottom.
      10991102 const workLogCount = workLogEntries.length;
      11001103 const scrollMessagesToBottom = useCallback((behavior: ScrollBehavior = "auto") => {
      11011104 const scrollContainer = messagesScrollRef.current;
      11021105 if (!scrollContainer) return;
      11031106 scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior });
      1107+ lastKnownScrollTopRef.current = scrollContainer.scrollTop;
      1108+ lastKnownScrollHeightRef.current = scrollContainer.scrollHeight;
      11041109 shouldAutoScrollRef.current = true;
      11051110 }, []);
      1111+ const requestAutoTailToBottom = useCallback(() => {
      1112+ if (pendingAutoScrollFrameRef.current !== null) return;
      1113+ pendingAutoScrollFrameRef.current = window.requestAnimationFrame(() => {
      1114+ pendingAutoScrollFrameRef.current = null;
      1115+ if (!shouldAutoScrollRef.current) return;
      1116+ scrollMessagesToBottom();
      greptile-apps[bot](GitHub profile, opens in a new tab)commented

      scrollMessagesToBottom() always uses behavior: "auto" (instant scroll) inside requestAnimationFrame, removing the smooth scrolling that existed before. Users will see jarring instant jumps during streaming instead of smooth auto-scroll.

      Suggested change
      1119+ scrollMessagesToBottom("smooth");
      @@ -1109,0 +1124,21 @@
      1124+ const atBottom = isScrollContainerAtBottom(scrollContainer);
      1125+
      1126+ if (atBottom) {
      1127+ shouldAutoScrollRef.current = true;
      1128+ } else if (shouldAutoScrollRef.current) {
      1129+ // While tailing, only relinquish control when the user scrolls upward.
      1130+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
      1131+ const contentHeightChanged =
      1132+ Math.abs(currentScrollHeight - lastKnownScrollHeightRef.current) > 1;
      1133+ if (scrolledUp && !contentHeightChanged) {
      1134+ shouldAutoScrollRef.current = false;
      1135+ }
      1136+ }
      1137+
      1138+ lastKnownScrollTopRef.current = currentScrollTop;
      1139+ lastKnownScrollHeightRef.current = currentScrollHeight;
      1140+ }, []);
      1141+ const onMessagesWheel = useCallback((event: WheelEvent<HTMLDivElement>) => {
      1142+ if (event.deltaY < 0) {
      1143+ shouldAutoScrollRef.current = false;
      1144+ }
      greptile-apps[bot](GitHub profile, opens in a new tab)commented

      Wheel handler disables auto-scroll on ANY upward wheel event, even when the user is already at the bottom and content is growing downward. This breaks tailing during streaming when users accidentally touch their trackpad/wheel.

    9. Cursor Bugbot has reviewed your changes and found 1 potential issue.

      Bugbot Autofix is [ON](https://www.cursor.com/dashboard?tab=bugbot). A Cloud Agent has been kicked off to fix the reported issue.
      @@ -1109,0 +1126,21 @@
      1126+ const atBottom = isScrollContainerAtBottom(scrollContainer);
      1127+
      1128+ if (!shouldAutoScrollRef.current && atBottom) {
      1129+ shouldAutoScrollRef.current = true;
      1130+ pendingUserScrollUpIntentRef.current = false;
      1131+ } else if (shouldAutoScrollRef.current && pendingUserScrollUpIntentRef.current) {
      1132+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
      1133+ if (scrolledUp) {
      1134+ shouldAutoScrollRef.current = false;
      1135+ }
      1136+ pendingUserScrollUpIntentRef.current = false;
      1137+ } else if (shouldAutoScrollRef.current && isPointerScrollActiveRef.current) {
      1138+ // Pointer-driven upward scroll means user takes control.
      1139+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
      1140+ if (scrolledUp) {
      1141+ shouldAutoScrollRef.current = false;
      1142+ }
      1143+ }
      1144+
      1145+ lastKnownScrollTopRef.current = currentScrollTop;
      1146+ }, []);

      Keyboard scroll-up fails to disable auto-scroll

      High Severity

      The onMessagesScroll handler only disables auto-scroll (shouldAutoScrollRef) when upward scroll is detected via wheel, pointer, or touch events. Keyboard scrolling (Page Up, Home, Arrow Up, spacebar in some contexts) fires a scroll event but never sets pendingUserScrollUpIntentRef or isPointerScrollActiveRef, so no branch in the handler matches, and shouldAutoScrollRef stays true. The next time messages arrive, the useLayoutEffect auto-scrolls back to the bottom, fighting the user's keyboard navigation. The old code avoided this by unconditionally updating shouldAutoScrollRef from isScrollContainerNearBottom on every scroll event.

      Additional Locations (1)

      Fix in Cursor Fix in Web

    10. Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

      • ✅ Fixed: Keyboard scroll-up fails to disable auto-scroll
        • Added a catch-all else-if branch in onMessagesScroll that detects upward scrolling when shouldAutoScrollRef is true and the container is not at bottom, covering keyboard, assistive technology, and any other scroll source not handled by the explicit wheel/pointer/touch intent flags.

      Create PR

      Or push these changes by commenting:

      @cursor push 6d56621512
      Preview (pingdotgg/codething-mvp@6d56621512)
      diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
      --- a/apps/web/src/components/ChatView.tsx
      +++ b/apps/web/src/components/ChatView.tsx
      @@ -1140,6 +1140,12 @@
             if (scrolledUp) {
               shouldAutoScrollRef.current = false;
             }
      +    } else if (shouldAutoScrollRef.current && !atBottom) {
      +      // Catch-all for keyboard, assistive technology, or any other scroll source.
      +      const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
      +      if (scrolledUp) {
      +        shouldAutoScrollRef.current = false;
      +      }
           }
       
           lastKnownScrollTopRef.current = currentScrollTop;
    11. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    12. juliusmarminge closed this

Sign in to join this conversation.