Tighten chat auto-tail to true bottom position #81
- @@ -1107,17 +1106,12 @@11071106 const scrollContainer = messagesScrollRef.current;11081107 if (!scrollContainer) return;1109- shouldAutoScrollRef.current = isScrollContainerNearBottom(scrollContainer);1108+ shouldAutoScrollRef.current = isScrollContainerAtBottom(scrollContainer);11101109 }, []);11111110 useLayoutEffect(() => {11121111 if (!activeThread?.id) return;11131112 scrollMessagesToBottom();11141113 }, [activeThread?.id, scrollMessagesToBottom]);1115- useEffect(() => {1116- if (!shouldAutoScrollRef.current) return;1117- scrollMessagesToBottom("smooth");1118- }, [messageCount, scrollMessagesToBottom]);1119- useEffect(() => {1120- if (phase !== "running") return;1114+ useLayoutEffect(() => {11211115 if (!shouldAutoScrollRef.current) return;1122- scrollMessagesToBottom("smooth");1123- }, [phase, workLogCount, scrollMessagesToBottom]);1116+ scrollMessagesToBottom();1117+ }, [activeThread?.messages, workLogCount, scrollMessagesToBottom]);
- apps/web/src/components/ChatView.tsx line 1174Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -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+ }
- @@ -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 }, []);
- @@ -1094,10 +1098,11 @@10941098 }10951099 }, [lastInvokedScriptByProjectId]);109611001097- // Auto-scroll on new messages1098- 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;@@ -1094,12 +1098,19 @@10941098 }10951099 }, [lastInvokedScriptByProjectId]);109611001097- // Auto-scroll on new messages1098- 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();@@ -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+ }
- @@ -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+ }, []);
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge closed this
Sign in to join this conversation.



Tighten chat auto-tail by using a 2px epsilon and update
ChatViewto auto-scroll only when at true bottom in chat-scroll.ts and ChatView.tsx#Rename
AUTO_SCROLL_BOTTOM_THRESHOLD_PXtoAUTO_SCROLL_BOTTOM_EPSILON_PXset to 2, replaceisScrollContainerNearBottomwithisScrollContainerAtBottom, and reworkChatViewauto-tail to honor bottom state and user scroll intent withrequestAnimationFrame-based tailing.📍Where to Start#
Start with
isScrollContainerAtBottomandAUTO_SCROLL_BOTTOM_EPSILON_PXin chat-scroll.ts, then reviewonMessagesScrolland related handlers in ChatView.tsx.Macroscope summarized 3031dfd.