Skip to content

fix(chat): preserve scroll anchor when user toggles collapsible thinking/subagent sections (#274731)#310966

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-274731-thinking-expand-layout-shift
Open

fix(chat): preserve scroll anchor when user toggles collapsible thinking/subagent sections (#274731)#310966
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-274731-thinking-expand-layout-shift

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

What — Manually expanding or collapsing a thinking/subagent/hook/markdown section in the chat list no longer snaps the viewport to the bottom. Previously-visible content stays visually put; the expand grows downward into unused space.

WhyChatListWidget._updateElementHeight auto-scrolls the list to the bottom whenever a row grows and the user was already pinned to the bottom. That's correct during streaming (content growing from below must stay visible) but wrong when the user clicks to expand a collapsed section: the expanded content appears above the anchor, so every added pixel shifts everything else upward (#274731).

How — Distinguish user-driven from programmatic height changes. ChatCollapsibleContentPart fires a bubbling CustomEvent('chatCollapsibleUserToggle') from its click handler; ChatListWidget records the timestamp on receive and skips _withPersistedAutoScroll within a 250 ms window. Programmatic setExpanded (used during streaming) doesn't dispatch the event, so auto-scroll during streaming is unchanged.

Test plan — Manual (from the issue): agent-mode prompt "Look at the git changes in the last 24 hours…", wait for streaming, scroll to bottom, click to expand the thinking section. Pre-fix: viewport jumps upward. Post-fix: content above stays put. Also verified streaming auto-scroll still works. Added 2 unit tests in chatThinkingContentPart.test.ts asserting the click dispatches exactly one bubbling event.

Applies to every ChatCollapsibleContentPart subclass, not just thinking.

Fixes #274731

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.

Expand Thinking section pushes chat layout upwards

2 participants