fix: keep chat pinned during delayed rendering
Keeps long historical sessions scrolled to the bottom after load Preserves bottom follow while assistant responses grow
This commit is contained in:
@@ -85,6 +85,7 @@ export const useChatScrollManager = ({
|
|||||||
}: UseChatScrollManagerOptions): UseChatScrollManagerResult => {
|
}: UseChatScrollManagerOptions): UseChatScrollManagerResult => {
|
||||||
const scrollRef = React.useRef<HTMLDivElement | null>(null);
|
const scrollRef = React.useRef<HTMLDivElement | null>(null);
|
||||||
const scrollEngine = useScrollEngine({ containerRef: scrollRef, isMobile });
|
const scrollEngine = useScrollEngine({ containerRef: scrollRef, isMobile });
|
||||||
|
const cancelScrollFollow = scrollEngine.cancelFollow;
|
||||||
|
|
||||||
const getPinThreshold = React.useCallback(() => {
|
const getPinThreshold = React.useCallback(() => {
|
||||||
const container = scrollRef.current;
|
const container = scrollRef.current;
|
||||||
@@ -196,9 +197,9 @@ export const useChatScrollManager = ({
|
|||||||
markAutoScroll(Math.max(0, bottom));
|
markAutoScroll(Math.max(0, bottom));
|
||||||
scrollEngine.scrollToPosition(Math.max(0, bottom), {
|
scrollEngine.scrollToPosition(Math.max(0, bottom), {
|
||||||
...options,
|
...options,
|
||||||
persistFollow: Boolean(options?.followBottom && sessionIsWorking),
|
persistFollow: Boolean(options?.followBottom),
|
||||||
});
|
});
|
||||||
}, [markAutoScroll, scrollEngine, sessionIsWorking]);
|
}, [markAutoScroll, scrollEngine]);
|
||||||
|
|
||||||
const scrollPinnedToBottom = React.useCallback((distanceFromBottom: number) => {
|
const scrollPinnedToBottom = React.useCallback((distanceFromBottom: number) => {
|
||||||
if (sessionIsWorking) {
|
if (sessionIsWorking) {
|
||||||
@@ -571,10 +572,10 @@ export const useChatScrollManager = ({
|
|||||||
// Maintain pin-to-bottom when content changes
|
// Maintain pin-to-bottom when content changes
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!sessionIsWorking) {
|
if (!sessionIsWorking) {
|
||||||
scrollEngine.cancelFollow();
|
cancelScrollFollow();
|
||||||
setFollowMode('none');
|
setFollowMode('none');
|
||||||
}
|
}
|
||||||
}, [scrollEngine, sessionIsWorking, setFollowMode]);
|
}, [cancelScrollFollow, sessionIsWorking, setFollowMode]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isSyncing) {
|
if (isSyncing) {
|
||||||
|
|||||||
Reference in New Issue
Block a user