Skip to content

🐛 fix: fix auto scroll in group#11734

Merged
arvinxx merged 3 commits intonextfrom
fix/group-issue
Jan 23, 2026
Merged

🐛 fix: fix auto scroll in group#11734
arvinxx merged 3 commits intonextfrom
fix/group-issue

Conversation

@arvinxx
Copy link
Copy Markdown
Member

@arvinxx arvinxx commented Jan 23, 2026

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

fix LOBE-3608

🔀 Description of Change

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

📸 Screenshots / Videos

Before After
... ...

📝 Additional Information

Summary by Sourcery

Improve chat auto-scroll behavior to better handle user messages and virtualized rendering.

Bug Fixes:

  • Scroll only to the latest user message when a new user message is sent, avoiding jumps when AI or multiple agents respond.
  • Preserve scroll position when auto-scroll is disabled after streaming ends to prevent position resets on DOM re-renders.
  • Ensure the AutoScroll/back-to-bottom control is always visible by placing it outside the virtualized list container and adjusting layout and debug overlays.

Enhancements:

  • Add a dedicated hook to manage scrolling to the latest user message in conversation views.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
lobehub Ready Ready Preview, Comment Jan 23, 2026 6:20pm

Request Review

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 23, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 23, 2026

Reviewer's Guide

Refines chat auto-scroll behavior so that the list only auto-scrolls when the user sends a new message, stabilizes scroll position when streaming ends, and moves the AutoScroll overlay outside the virtualized list to prevent it from being recycled and to keep the back-to-bottom control visible.

Sequence diagram for updated chat auto scroll on user message

sequenceDiagram
  actor User
  participant ConversationInput
  participant ConversationStore
  participant VirtualizedList
  participant useScrollToUserMessage
  participant VList

  User->>ConversationInput: Type and send message
  ConversationInput->>ConversationStore: append user message
  ConversationStore-->>VirtualizedList: update displayMessages
  VirtualizedList->>VirtualizedList: compute isLastMessageFromUser
  VirtualizedList->>useScrollToUserMessage: call with dataSourceLength, isLastMessageFromUser, scrollToIndex
  useScrollToUserMessage->>useScrollToUserMessage: detect hasNewMessage
  alt last message is from user
    useScrollToUserMessage->>VList: scrollToIndex(dataSourceLength - 2, align start, smooth true)
  else last message is from agent
    useScrollToUserMessage--xVList: no auto scroll
  end

  note over User,VList: Auto scroll is only triggered for new user messages, not for agent responses
Loading

Sequence diagram for preserving scroll when streaming ends

sequenceDiagram
  participant VList
  participant AutoScroll
  participant useAutoScroll
  participant ScrollContainer

  VList->>AutoScroll: render with enabled true
  AutoScroll->>useAutoScroll: useAutoScroll(enabled true, deps)
  useAutoScroll->>ScrollContainer: attach scroll listener
  loop streaming messages
    ScrollContainer->>useAutoScroll: scroll events
    useAutoScroll->>useAutoScroll: manage userHasScrolled
  end

  AutoScroll->>AutoScroll: streaming ends
  AutoScroll->>useAutoScroll: re render with enabled false
  useAutoScroll->>useAutoScroll: detect enabled transitioned from true to false
  useAutoScroll->>ScrollContainer: read currentScrollTop
  useAutoScroll->>useAutoScroll: set isAutoScrollingRef true
  useAutoScroll->>ScrollContainer: requestAnimationFrame restore scrollTop
  useAutoScroll->>useAutoScroll: reset isAutoScrollingRef false

  note over VList,ScrollContainer: Scroll position is preserved across DOM changes when streaming stops
Loading

Class diagram for updated chat auto scroll components and hooks

classDiagram
  class VirtualizedList {
    <<component>>
    - virtuaRef : VListHandle
    - scrollEndTimerRef : Timeout | null
    - displayMessages : Message[]
    - lastMessage : Message | undefined
    - isLastMessageFromUser : boolean
    + VirtualizedList(props dataSource : string[], itemContent : function) ReactElement
  }

  class useScrollToUserMessage {
    <<hook>>
    - prevLengthRef : number
    + useScrollToUserMessage(dataSourceLength : number, isLastMessageFromUser : boolean, scrollToIndex : function) void
  }

  class AutoScroll {
    <<component>>
    - shouldAutoScroll : boolean
    - atBottom : boolean
    - dbMessages : Message[]
    - lastMessageContentLength : number
    + AutoScroll() ReactElement
    + scrollToBottom(force : boolean) void
  }

  class useAutoScroll {
    <<hook>>
    - ref : HTMLElement | null
    - userHasScrolled : boolean
    - isAutoScrollingRef : boolean
    - prevEnabledRef : boolean
    + useAutoScroll(enabled : boolean, deps : any[]) HTMLElement | null
    + handleScroll() void
    + scrollToBottom(force : boolean) void
  }

  class VList {
    <<component>>
    + scrollToIndex(index : number, options : ScrollOptions) void
  }

  class BackBottom {
    <<component>>
    + BackBottom(onScrollToBottom : function, visible : boolean) ReactElement
  }

  VirtualizedList ..> useScrollToUserMessage : uses
  VirtualizedList ..> AutoScroll : renders
  VirtualizedList ..> VList : renders
  AutoScroll ..> useAutoScroll : uses
  AutoScroll ..> BackBottom : renders
  useScrollToUserMessage ..> VList : calls scrollToIndex

  class Message {
    + id : string
    + role : string
    + content : string
  }

  VirtualizedList --> "*" Message : displayMessages
  AutoScroll --> "*" Message : dbMessages
Loading

File-Level Changes

Change Details Files
Change auto-scroll trigger logic to only scroll on new user messages instead of on any new message.
  • Remove local prev-data-length tracking in the virtualized list component.
  • Read the last displayed message from the conversation store and derive whether it is from the user.
  • Introduce and use a dedicated useScrollToUserMessage hook that watches list length and last-message role to decide when to scroll.
  • Invoke scrollToIndex through the new hook, targeting the user’s message rather than agent replies.
src/features/Conversation/ChatList/components/VirtualizedList.tsx
src/features/Conversation/ChatList/hooks/useScrollToUserMessage.ts
Reposition AutoScroll and its debug UI so it is independent of individual list items and not affected by virtualization recycling.
  • Wrap VList in a relatively positioned container div so overlay elements can be absolutely positioned.
  • Render a single AutoScroll component outside VList so it is not unmounted with virtual rows and its BackBottom button remains visible when the user scrolls up.
  • Update AutoScroll debug inspector markup so the threshold visualization is absolutely positioned at the bottom of the viewport area instead of within a per-item container.
  • Adjust DebugInspector bottom offset to account for the new layout.
src/features/Conversation/ChatList/components/VirtualizedList.tsx
src/features/Conversation/ChatList/components/AutoScroll/index.tsx
src/features/Conversation/ChatList/components/AutoScroll/DebugInspector.tsx
Preserve scroll position when auto-scroll is disabled after streaming ends to avoid jumps on DOM re-render.
  • Track previous enabled value in the useAutoScroll hook.
  • Detect transitions from enabled=true to enabled=false and capture the current scrollTop.
  • Use requestAnimationFrame to restore scrollTop across DOM changes while toggling an isAutoScrolling guard to avoid treating this as user scroll.
src/hooks/useAutoScroll.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@dosubot dosubot bot added the 🐛 Bug label Jan 23, 2026
@gru-agent
Copy link
Copy Markdown
Contributor

gru-agent bot commented Jan 23, 2026

TestGru Assignment

Summary

Link CommitId Status Reason
Detail 92abaec 🚫 Skipped No files need to be tested {"src/features/Conversation/ChatList/components/AutoScroll/DebugInspector.tsx":"File path does not match include patterns.","src/features/Conversation/ChatList/components/AutoScroll/index.tsx":"File path does not match include patterns.","src/features/Conversation/ChatList/components/VirtualizedList.tsx":"File path does not match include patterns.","src/features/Conversation/ChatList/hooks/useScrollToUserMessage.test.ts":"File path does not match include patterns.","src/features/Conversation/ChatList/hooks/useScrollToUserMessage.ts":"File path does not match include patterns.","src/hooks/useAutoScroll.test.ts":"File path does not match include patterns.","src/hooks/useAutoScroll.ts":"File path does not match include patterns."}

History Assignment

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In useScrollToUserMessage, the scrollToIndex(dataSourceLength - 2, ...) call can produce a negative index when dataSourceLength < 2; consider guarding on dataSourceLength >= 2 before attempting to scroll.
  • The scrollToIndex option type currently uses { align?: string; smooth?: boolean }; you may want to narrow align to the actual allowed values for the underlying virtual list API (e.g. 'start' | 'center' | 'end'), which will help catch misuse at compile time.
  • In VirtualizedList, displayMessages is re-selected from useConversationStore even though dataSource is already provided as a prop; if these are meant to stay in sync, consider deriving isLastMessageFromUser from dataSource or passing isLastMessageFromUser in as a prop to avoid subtle desynchronization issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `useScrollToUserMessage`, the `scrollToIndex(dataSourceLength - 2, ...)` call can produce a negative index when `dataSourceLength < 2`; consider guarding on `dataSourceLength >= 2` before attempting to scroll.
- The `scrollToIndex` option type currently uses `{ align?: string; smooth?: boolean }`; you may want to narrow `align` to the actual allowed values for the underlying virtual list API (e.g. `'start' | 'center' | 'end'`), which will help catch misuse at compile time.
- In `VirtualizedList`, `displayMessages` is re-selected from `useConversationStore` even though `dataSource` is already provided as a prop; if these are meant to stay in sync, consider deriving `isLastMessageFromUser` from `dataSource` or passing `isLastMessageFromUser` in as a prop to avoid subtle desynchronization issues.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -0,0 +1,224 @@
import { act, renderHook } from '@testing-library/react';
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.17%. Comparing base (550acc2) to head (bfa1a26).
⚠️ Report is 44 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next   #11734      +/-   ##
==========================================
+ Coverage   74.15%   74.17%   +0.01%     
==========================================
  Files        1191     1193       +2     
  Lines       94815    94886      +71     
  Branches    12500    10909    -1591     
==========================================
+ Hits        70313    70384      +71     
  Misses      24412    24412              
  Partials       90       90              
Flag Coverage Δ
app 67.21% <100.00%> (+0.03%) ⬆️
database 91.44% <ø> (ø)
packages/agent-runtime 90.20% <ø> (ø)
packages/context-engine 85.36% <ø> (ø)
packages/conversation-flow 92.28% <ø> (ø)
packages/file-loaders 88.66% <ø> (ø)
packages/memory-user-memory 69.68% <ø> (ø)
packages/model-bank 100.00% <ø> (ø)
packages/model-runtime 86.72% <ø> (ø)
packages/prompts 79.33% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 93.22% <ø> (ø)
packages/web-crawler 95.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 67.96% <ø> (ø)
Services 50.58% <ø> (ø)
Server 67.71% <ø> (ø)
Libs 40.36% <ø> (ø)
Utils 93.60% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

/>
<>
{/* Debug: 底部指示线 */}
{OPEN_DEV_INSPECTOR && (
@arvinxx arvinxx changed the title 🐛 fix: fix auto scroll 🐛 fix: fix auto scroll in group Jan 23, 2026
@arvinxx arvinxx merged commit 892fa9f into next Jan 23, 2026
37 of 40 checks passed
@arvinxx arvinxx deleted the fix/group-issue branch January 23, 2026 12:00
@lobehubbot
Copy link
Copy Markdown
Member

❤️ Great PR @arvinxx ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

lobehubbot pushed a commit that referenced this pull request Jan 23, 2026
## [Version&nbsp;2.0.0-next.351](v2.0.0-next.350...v2.0.0-next.351)
<sup>Released on **2026-01-23**</sup>

#### 🐛 Bug Fixes

- **misc**: Fix auto scroll.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Fix auto scroll, closes [#11734](#11734) ([892fa9f](892fa9f))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Copy Markdown
Member

🎉 This PR is included in version 2.0.0-next.351 🎉

The release is available on:

Your semantic-release bot 📦🚀

JamieStivala pushed a commit to jaworldwideorg/OneJA-Bot that referenced this pull request Jan 23, 2026
## [Version&nbsp;1.154.0](v1.153.1...v1.154.0)
<sup>Released on **2026-01-23**</sup>

#### ♻ Code Refactoring

- **misc**: Migrate AI Rules to Claude Code Skills.

#### ✨ Features

- **database**: Extended async task with metadata and parent id, added index.
- **misc**: Remove NextAuth.

#### 🐛 Bug Fixes

- **copilot**: History popover not refreshing when agentId changes.
- **editor**: Prevent crash when toggling enableInputMarkdown setting.
- **home**: Use correct CreateGroupModal for session group creation.
- **model-runtime**: Handle null content in anthropic message builder.
- **ModelSelect**: Resolve tooltip hover causing popup to close.
- **pdf**: Ensure worker config before Document render.
- **store**: Delete message before regeneration.
- **misc**: Fix auto scroll, fix favorite refresh bug and group topic refresh issue, fixed the agent group builder tools excaution edge case crash, page content switch mismatch, when use market group, the group sys role was not used.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Migrate AI Rules to Claude Code Skills, closes [lobehub#11737](https://github.com/jaworldwideorg/OneJA-Bot/issues/11737) ([346fc46](346fc46))

#### What's improved

* **database**: Extended async task with metadata and parent id, added index, closes [lobehub#11712](https://github.com/jaworldwideorg/OneJA-Bot/issues/11712) ([31d2f26](31d2f26))
* **misc**: Remove NextAuth, closes [lobehub#11732](https://github.com/jaworldwideorg/OneJA-Bot/issues/11732) ([1eff864](1eff864))

#### What's fixed

* **copilot**: History popover not refreshing when agentId changes, closes [lobehub#11731](https://github.com/jaworldwideorg/OneJA-Bot/issues/11731) ([64f39e7](64f39e7))
* **editor**: Prevent crash when toggling enableInputMarkdown setting, closes [lobehub#11755](https://github.com/jaworldwideorg/OneJA-Bot/issues/11755) ([ea5eed8](ea5eed8))
* **home**: Use correct CreateGroupModal for session group creation, closes [lobehub#11752](https://github.com/jaworldwideorg/OneJA-Bot/issues/11752) ([36bcc50](36bcc50))
* **model-runtime**: Handle null content in anthropic message builder, closes [lobehub#11756](https://github.com/jaworldwideorg/OneJA-Bot/issues/11756) ([539753a](539753a))
* **ModelSelect**: Resolve tooltip hover causing popup to close, closes [lobehub#11742](https://github.com/jaworldwideorg/OneJA-Bot/issues/11742) ([1b73f14](1b73f14))
* **pdf**: Ensure worker config before Document render, closes [lobehub#11746](https://github.com/jaworldwideorg/OneJA-Bot/issues/11746) ([ad34072](ad34072))
* **store**: Delete message before regeneration, closes [lobehub#11760](https://github.com/jaworldwideorg/OneJA-Bot/issues/11760) ([a8a6300](a8a6300))
* **misc**: Fix auto scroll, closes [lobehub#11734](https://github.com/jaworldwideorg/OneJA-Bot/issues/11734) ([892fa9f](892fa9f))
* **misc**: Fix favorite refresh bug and group topic refresh issue, closes [lobehub#11745](https://github.com/jaworldwideorg/OneJA-Bot/issues/11745) ([5d115ef](5d115ef))
* **misc**: Fixed the agent group builder tools excaution edge case crash, closes [lobehub#11735](https://github.com/jaworldwideorg/OneJA-Bot/issues/11735) ([5de4742](5de4742))
* **misc**: Page content switch mismatch, closes [lobehub#11758](https://github.com/jaworldwideorg/OneJA-Bot/issues/11758) ([fdc8f95](fdc8f95))
* **misc**: When use market group, the group sys role was not used, closes [lobehub#11739](https://github.com/jaworldwideorg/OneJA-Bot/issues/11739) ([afc76f9](afc76f9))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 Bug released on @next size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants