Skip to content

Fix scroll behavior for inline feedback messages#1787

Merged
mabashian merged 1 commit intomainfrom
mabashian/AAP-44636-feedback-scroll
Nov 12, 2025
Merged

Fix scroll behavior for inline feedback messages#1787
mabashian merged 1 commit intomainfrom
mabashian/AAP-44636-feedback-scroll

Conversation

@mabashian
Copy link
Member

Jira Issue: https://issues.redhat.com/browse/AAP-44636

Assisted-by: Claude code

Description

When users clicked thumbs up/down on previous messages in the chatbot, the view would auto-scroll to the bottom instead of staying anchored on the message being rated. This caused the "Thank you for your feedback!" confirmation message to appear off-screen, disrupting the user experience.

Solution

Fixed the scroll behavior by implementing a two-part solution:

  1. Conditional scroll triggering (AnsibleChatbot.tsx)

Modified the useEffect hook to only trigger auto-scroll when the scrollToHere flag is explicitly set on the last message, preventing unwanted scrolling when feedback messages are added inline.

  useEffect(() => {
      // Only auto-scroll if the last message has scrollToHere flag set
      // This prevents unwanted scrolling when feedback messages are added inline
      const lastMessage = messages[messages.length - 1];
      if (lastMessage?.scrollToHere) {
          scrollToBottom();
      }
  }, [messages]);
  1. Smart flag management (useChatbot.ts)

Updated the addMessage function to only set the scrollToHere flag when messages are appended to the end, not when they're inserted inline using the addAfter parameter (which is used for feedback messages).

// Only set scrollToHere if message is added at the end (not inserted inline)
newMessage.scrollToHere = !isStreamingSupported() && !addAfter;
  1. Unit tests (AnsibleChatbot.test.tsx)

Added comprehensive unit tests to verify:

  • Feedback messages appear inline without triggering scroll
  • New chat messages still trigger scroll as expected

Testing

All existing tests pass (41 tests in aap_chatbot, 39 tests in ansible_ai_connect_chatbot), plus 2 new tests per implementation verifying the scroll fix.

Production deployment

  • This code change is ready for production on its own
  • This code change requires the following considerations before going to production:

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 7, 2025

@mabashian
Copy link
Member Author

Here's the change in action:

chatbot_react_scroll

@mabashian mabashian merged commit a67fa74 into main Nov 12, 2025
12 checks passed
@mabashian mabashian deleted the mabashian/AAP-44636-feedback-scroll branch November 12, 2025 14:16
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.

2 participants