mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-11 08:16:00 +08:00
fix(chat): stabilize long-history scroll-up pagination behavior
- fix top-pagination lockups by only locking when older messages are actually fetched - make fetched older messages visible immediately by increasing `visibleMessageCount` on prepend - prevent unintended auto-scroll-to-bottom during older-message loading and scroll restore - replace state-based pagination offset with a ref to avoid stale offset/reload side effects - ensure initial auto-scroll runs only after initial session load completes - reset top-load lock/restore state and visible window when switching sessions - loosen top-lock release near the top to avoid requiring a full down/up cycle
This commit is contained in:
@@ -208,13 +208,17 @@ export function useChatSessionState({
|
|||||||
sessionProvider,
|
sessionProvider,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (moreMessages.length > 0) {
|
if (moreMessages.length === 0) {
|
||||||
pendingScrollRestoreRef.current = {
|
return false;
|
||||||
height: previousScrollHeight,
|
|
||||||
top: previousScrollTop,
|
|
||||||
};
|
|
||||||
setSessionMessages((previous) => [...moreMessages, ...previous]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pendingScrollRestoreRef.current = {
|
||||||
|
height: previousScrollHeight,
|
||||||
|
top: previousScrollTop,
|
||||||
|
};
|
||||||
|
setSessionMessages((previous) => [...moreMessages, ...previous]);
|
||||||
|
// Keep the rendered window in sync with top-pagination so newly loaded history becomes visible.
|
||||||
|
setVisibleMessageCount((previousCount) => previousCount + moreMessages.length);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
isLoadingMoreRef.current = false;
|
isLoadingMoreRef.current = false;
|
||||||
@@ -239,6 +243,10 @@ export function useChatSessionState({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topLoadLockRef.current) {
|
if (topLoadLockRef.current) {
|
||||||
|
// After a top-load restore, release the lock once user has moved away from absolute top.
|
||||||
|
if (container.scrollTop > 20) {
|
||||||
|
topLoadLockRef.current = false;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +271,9 @@ export function useChatSessionState({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pendingInitialScrollRef.current = true;
|
pendingInitialScrollRef.current = true;
|
||||||
|
topLoadLockRef.current = false;
|
||||||
|
pendingScrollRestoreRef.current = null;
|
||||||
|
setVisibleMessageCount(INITIAL_VISIBLE_MESSAGES);
|
||||||
setIsUserScrolledUp(false);
|
setIsUserScrolledUp(false);
|
||||||
}, [selectedProject?.name, selectedSession?.id]);
|
}, [selectedProject?.name, selectedSession?.id]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user