Skip to content

Chat scrolls to bottom on every user message, even when scrolled up to read history #234

@DylanShang

Description

@DylanShang

Describe the bug
Every time a user message is sent, the chat view forcibly
smooth-scrolls
to the bottom — regardless of the user's current scroll position.
This makes it impossible to stay at a specific point in the
conversation
while waiting for a response.

Root cause (identified in minified bundle)
In the chat component's useLayoutEffect, the scroll is
triggered
whenever the last message role is "user":

const justSentUserMsg = messages.length > 0 &&                   
  messages[messages.length - 1].role === "user"                  
                                                                 
if (contentGrew && (isFirstLoad || wasAtBottom ||                
justSentUserMsg)) {                                              
  container.scrollTo({ top: scrollHeight, behavior: "smooth" })  
}  

The justSentUserMsg condition bypasses the wasAtBottom guard,
so scroll always fires on send — even if the user has scrolled
up.

Expected behavior
Only scroll to bottom if the user was already near the bottom
(wasAtBottom === true) before sending. Sending a message should
not override a deliberate scroll position.

Suggested fix
Remove justSentUserMsg from the OR condition, or gate it behind
wasAtBottom:

if (contentGrew && (isFirstLoad || wasAtBottom)) {               
 container.scrollTo({ top: scrollHeight, behavior: "smooth" })  
}  

Environment

  • agentapi version: 0.12.2
  • Agent: claude

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions