story-kit: fix chat auto-scroll to bottom on new messages (bug 248)
Correct lastScrollTopRef assignment in scrollToBottom to read back the browser-capped scrollTop value instead of using scrollHeight, which was causing handleScroll to incorrectly detect upward scrolling and disable auto-scroll. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -390,7 +390,11 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
|
||||
const element = scrollContainerRef.current;
|
||||
if (element) {
|
||||
element.scrollTop = element.scrollHeight;
|
||||
lastScrollTopRef.current = element.scrollHeight;
|
||||
// Read scrollTop back after assignment: the browser caps it at
|
||||
// (scrollHeight - clientHeight), so storing scrollHeight would
|
||||
// make handleScroll incorrectly interpret the next scroll event
|
||||
// as an upward scroll and disable auto-scrolling.
|
||||
lastScrollTopRef.current = element.scrollTop;
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user