Implemented a UX enhancement for the chat message display behavior that positions newest messages at the top of the viewport instead of auto-scrolling to the bottom.
- Replaced bottom-scroll logic with top-scroll positioning
- Added state tracking for scroll behavior:
shouldScrollToNewest: Triggers scroll to newest messagelastMessageCount: Tracks message count changesisUserScrolling: Prevents auto-scroll during manual scrolling
- Implemented smooth scroll animation using
scrollIntoViewwithblock: 'start' - Added user scroll detection to preserve manual scroll position
- Enhanced message loading to position at newest message after session load
- Added
data-message-itemattributes to each message for scroll targeting - Wrapped streaming messages with the same data attribute for consistent behavior
- Removed individual auto-scroll logic to prevent conflicts
- Centralized scroll behavior in the main chat session component
- Added smooth scroll behavior to scroll area viewport
- Implemented scroll margin for better positioning
- Added transitions for smooth scroll animations
- Prevented layout shifts during scroll operations
- New Message Detection: Tracks when message count increases
- Smooth Animation: Uses
scrollIntoViewwith smooth behavior - User Interaction Handling: Detects manual scrolling and preserves position
- Timing Optimization: 50ms delay ensures DOM updates before scrolling
- Fallback Mechanism: Falls back to bottom scroll if message elements not found
- ✅ Newest messages appear at top of viewport
- ✅ Smooth scroll animations
- ✅ Manual scroll preservation
- ✅ Works with streaming messages
- ✅ No layout shifts
- ✅ Performance optimized
- Uses modern
scrollIntoViewAPI with smooth behavior - CSS
scroll-behavior: smoothfor enhanced smoothness - Graceful fallback for older browsers
- Tested with message sending and receiving
- Verified smooth scroll animations
- Confirmed manual scroll preservation
- Validated streaming message behavior
- Checked performance with multiple messages
frontend-next/src/components/workspace/chat/chat-session.tsxfrontend-next/src/components/workspace/chat/chat-message.tsxfrontend-next/src/components/workspace/chat/streaming-message.tsxfrontend-next/src/app/globals.css
The enhancement is automatically active for all chat sessions. Users will notice:
- New messages appear at the top of the visible area
- Smooth animations when new messages arrive
- Ability to scroll down to view older messages
- Preserved scroll position during manual navigation