Skip to content

fix(mothership): keep scroll position when user scrolls up during streaming#5639

Merged
TheodoreSpeaks merged 2 commits into
stagingfrom
debug/sticky-mothership-scroll
Jul 13, 2026
Merged

fix(mothership): keep scroll position when user scrolls up during streaming#5639
TheodoreSpeaks merged 2 commits into
stagingfrom
debug/sticky-mothership-scroll

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • Scrolling up during a streaming response no longer gets dragged back down. react-virtual's row-resize compensation was scrolling the viewport down in lockstep with the growing last row (it treats any resized row that starts above the viewport as "content above changed", but the streaming row grows at its bottom edge). Disabled it for the last row via shouldAdjustScrollPositionOnItemSizeChange — set as an instance property, since it's silently ignored when passed as a useVirtualizer option.
  • useAutoScroll: re-attach now requires downward motion, so a small upward flick's own scroll event (still within the 5px re-attach window) can't instantly undo the detach.
  • Same direction gate applied to the subagent BoundedViewport sticky scroll.

Type of Change

  • Bug fix

Testing

Repro'd and verified live against dev with scripted wheel gestures: upward scroll mid-stream now holds position while content grows below; pinned-at-bottom following and scroll-back-down re-attach still work. bun run lint:check and bun run check:api-validation:strict pass.

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)

🤖 Generated with Claude Code

https://claude.ai/code/session_01HE5rFzcWAZ3HwCKneEgD9n

@vercel

vercel Bot commented Jul 13, 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 Jul 13, 2026 6:45pm

Request Review

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Localized chat scroll and virtualizer behavior; no auth, data, or API changes.

Overview
Fixes the viewport being pulled back down while a response streams after the user scrolls up.

Mothership chat: Sets virtualizer.shouldAdjustScrollPositionOnItemSizeChange on the virtualizer instance (not as a hook option) so react-virtual does not compensate scroll when the last row resizes. That row grows at the bottom edge; the default behavior treated it like content above the viewport changing and scrolled down in lockstep.

useAutoScroll: Re-attaching sticky follow now requires scrolling downward once detached, not only being within the bottom threshold—so a small upward flick cannot immediately re-stick via its own scroll event.

Subagent BoundedViewport: Applies the same downward-motion gate before re-enabling stick-to-bottom during streaming.

Reviewed by Cursor Bugbot for commit edca7bf. Bugbot is set up for automated code reviews on this repo. Configure here.

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes chat auto-scroll behavior during streaming. The main changes are:

  • Disables virtualizer size compensation for the last chat row.
  • Requires downward movement before reattaching the main chat auto-scroll.
  • Applies the same downward reattach gate to the bounded subagent viewport.

Confidence Score: 4/5

The changed scroll reattach paths can leave streaming views detached after content height changes.

  • The main chat hook blocks reattach when the bottom moves into range through row shrink or browser clamping.
  • The bounded subagent viewport has the same failure mode with less state to recover from.
  • The virtualizer override did not show a concrete breakage from the inspected context.

apps/sim/hooks/use-auto-scroll.ts; apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/agent-group.tsx

Important Files Changed

Filename Overview
apps/sim/hooks/use-auto-scroll.ts Adds a downward-motion reattach gate to the main streaming auto-scroll hook; height shrink and clamp paths can leave sticky mode disabled at the bottom.
apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/agent-group.tsx Adds the same direction gate to the bounded subagent viewport, where resized content can keep the local chase detached.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsx Overrides the virtualizer instance hook to skip size-change scroll compensation for the last row.

Reviews (1): Last reviewed commit: "fix(mothership): keep scroll position wh..." | Re-trigger Greptile

Comment thread apps/sim/hooks/use-auto-scroll.ts
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes streaming chat scroll behavior so scrolling up no longer gets pulled back down. The main changes are:

  • Adds direction-aware reattach logic to the shared auto-scroll hook.
  • Applies the same sticky-scroll gate to bounded agent-group viewports.
  • Overrides virtualizer resize compensation for the streaming last row.

Confidence Score: 4/5

The virtualizer resize predicate needs a fix before merging.

  • Non-last row resizes can still adjust the viewport while the user scrolls upward.
  • The new reattach gates also have edge cases where a visually bottomed viewport can remain detached.
  • No security-sensitive behavior changed.

apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsx

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/agent-group.tsx Adds downward-motion gating before reattaching sticky bottom behavior in nested agent viewports.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsx Disables virtualizer resize compensation for the streaming last row, but the replacement predicate drops part of the default backward-scroll behavior.
apps/sim/hooks/use-auto-scroll.ts Requires downward movement before reattaching after user-detached scroll state.

Reviews (1): Last reviewed commit: "fix(mothership): keep scroll position wh..." | Re-trigger Greptile

Comment thread apps/sim/hooks/use-auto-scroll.ts
@TheodoreSpeaks TheodoreSpeaks merged commit 8853b0c into staging Jul 13, 2026
17 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the debug/sticky-mothership-scroll branch July 13, 2026 22:24
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