fix(acp-client): fix auto-scroll bugs on replay, clear, and streaming#170
Merged
fix(acp-client): fix auto-scroll bugs on replay, clear, and streaming#170
Conversation
Three related bugs all stemmed from stale isAtBottomRef state: 1. Scrolled to top on refresh/replay — prepareForReplay() clears items but isAtBottomRef stays false from previous scroll position, so new replay messages don't auto-scroll. 2. Bouncing near bottom — ResizeObserver and MutationObserver fire between RAF callbacks, scroll events briefly set isAtBottom=false, next observer skips auto-scroll. 3. Lost scroll on tool call expansion — same stale-ref mechanism. Fixes: - Add resetToBottom() to useAutoScroll return value for clearing stale scroll state after replay/clear - Fix RAF callback to re-check actual scroll geometry at execution time instead of relying solely on potentially stale isAtBottomRef - Add useEffect in AgentPanel to call resetToBottom when items go from >0 to 0 (replay clear signal) - Add useEffect in AgentPanel to call resetToBottom when session transitions from replaying to ready/prompting (replay complete) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resetToBottom()touseAutoScrollhook and wired it intoAgentPanelto reset stale scroll tracking when items are cleared (replay) or session finishes replayingisAtBottomRef, which can go stale from browser layout shifts between observer callbacksuseEffectthat scrolls to bottom when session transitions fromreplayingtoready/promptingRoot cause
All three bugs stemmed from
isAtBottomRefgoing stale between observer callbacks and DOM updates.prepareForReplay()clears items (async React state), but the ref retains the user's old scroll position, causing subsequent messages to not auto-scroll.Changes
useAutoScroll.ts: AddedresetToBottom(), fixed RAF to useisAtBottomRef.current || checkIsAtBottom(el)AgentPanel.tsx: Two newuseEffecthooks for replay clear and replay completeuseAutoScroll.test.ts: 4 new tests (resetToBottom, RAF geometry re-check)AgentPanel.test.tsx: 5 new tests (replay clear, replay complete, no false positives)Validation
pnpm lintpnpm typecheckpnpm testUI Compliance Checklist (Required for UI changes)
Exceptions (If any)
Agent Preflight (Required)
Classification
External References
N/A: Bug fix to internal scroll behavior hook. No external APIs or libraries involved beyond standard browser APIs (ResizeObserver, MutationObserver, requestAnimationFrame).
Codebase Impact Analysis
packages/acp-client/src/hooks/useAutoScroll.ts— AddedresetToBottom()to return value; fixed RAF callback to re-check geometrypackages/acp-client/src/components/AgentPanel.tsx— Two newuseEffecthooks wiringresetToBottomto replay lifecycle eventspackages/acp-client/src/hooks/useAutoScroll.test.ts— 4 new testspackages/acp-client/src/components/AgentPanel.test.tsx— 5 new testsDocumentation & Specs
N/A: Internal bug fix to scroll behavior. No public API changes, no spec changes, no documentation references to scroll behavior.
Constitution & Risk Check
bottomThresholdis configurable viaUseAutoScrollOptions. No new hardcoded values introduced.Generated with Claude Code