refactor(chat): enhance scroll management (#174)

- Add bottom detection with epsilon tolerance for precise positioning
- Introduce pending anchor restoration for seamless session switching
Include active turn anchor and spacer height in message store
This commit is contained in:
Bohdan Triapitsyn
2026-01-18 18:00:19 +02:00
committed by GitHub
parent 24969ba856
commit 85f41c39c1
3 changed files with 81 additions and 42 deletions
@@ -109,22 +109,6 @@ export const ChatContainer: React.FC = () => {
setIsLoadingOlder(false);
}, [currentSessionId]);
const lastScrolledSessionRef = React.useRef<string | null>(null);
React.useLayoutEffect(() => {
if (!currentSessionId || currentSessionId === lastScrolledSessionRef.current) {
return;
}
lastScrolledSessionRef.current = currentSessionId;
// Only scroll to bottom if there's no active anchor (anchor handles its own scroll)
if (!hasActiveAnchor) {
const container = scrollRef.current;
if (container) {
container.scrollTop = container.scrollHeight - container.clientHeight;
}
}
}, [currentSessionId, scrollRef, hasActiveAnchor]);
const handleLoadOlder = React.useCallback(async () => {
if (!currentSessionId || isLoadingOlder) {
return;