feat(FN-4336): complete Step 2 — defer visibility re-anchor settle pass

Fusion-Task-Id: FN-4336
Fusion-Task-Lineage: d96c9da9-e355-4dc0-bf8c-451a917b0270
This commit is contained in:
Fusion
2026-05-13 09:27:48 -07:00
committed by gsxdsm
parent f52e3cfada
commit ce652fb064

View File

@@ -960,6 +960,7 @@ export function ChatView({ projectId, addToast, experimentalFeatures }: ChatView
const isUserScrollingRef = useRef(false);
const lastAnchoredThreadStateRef = useRef<{ threadId: string; loaded: boolean; hasMessages: boolean } | null>(null);
const previousChatScopeRef = useRef<"direct" | "rooms" | null>(null);
const visibilityReanchorTimeoutRef = useRef<number | null>(null);
const hideSkillMenuTimeoutRef = useRef<number | null>(null);
const messagesContainerRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLTextAreaElement>(null);
@@ -1334,6 +1335,23 @@ export function ChatView({ projectId, addToast, experimentalFeatures }: ChatView
anchorToBottom(messagesContainer);
isUserScrollingRef.current = false;
setIsUserScrolling(false);
if (visibilityReanchorTimeoutRef.current !== null) {
window.clearTimeout(visibilityReanchorTimeoutRef.current);
visibilityReanchorTimeoutRef.current = null;
}
visibilityReanchorTimeoutRef.current = window.setTimeout(() => {
visibilityReanchorTimeoutRef.current = null;
if (isUserScrollingRef.current) {
return;
}
const connectedContainer = messagesContainerRef.current;
if (!connectedContainer) {
return;
}
anchorToBottom(connectedContainer);
}, 250);
};
const onVisibilityChange = () => {
@@ -1349,6 +1367,10 @@ export function ChatView({ projectId, addToast, experimentalFeatures }: ChatView
return () => {
document.removeEventListener("visibilitychange", onVisibilityChange);
window.removeEventListener("pageshow", reAnchorToLatest);
if (visibilityReanchorTimeoutRef.current !== null) {
window.clearTimeout(visibilityReanchorTimeoutRef.current);
visibilityReanchorTimeoutRef.current = null;
}
};
}, [isMobile, activeSession, roomThreadActive, anchorToBottom]);