fix(chat-switch): seed lastPendingCountRef from outbox to suppress mount scroll
This commit is contained in:
@@ -304,7 +304,6 @@ export function ConversationPage() {
|
|||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const composerRef = useRef<HTMLTextAreaElement>(null);
|
const composerRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (firstUnreadComputedRef.current) return;
|
if (firstUnreadComputedRef.current) return;
|
||||||
if (!id || messages.length === 0) return;
|
if (!id || messages.length === 0) return;
|
||||||
@@ -719,7 +718,12 @@ export function ConversationPage() {
|
|||||||
// now, so we have to call it explicitly. Tracked via a ref so we only
|
// now, so we have to call it explicitly. Tracked via a ref so we only
|
||||||
// scroll when the count actually grew (not on every render where it
|
// scroll when the count actually grew (not on every render where it
|
||||||
// happens to be > 0).
|
// happens to be > 0).
|
||||||
const lastPendingCountRef = useRef(0);
|
// Initialize from the current pending count rather than 0 so we don't
|
||||||
|
// fire scrollToIndex(LAST) on the very first render of a chat that
|
||||||
|
// already has outbox-queued items. Only growth of `pending.length`
|
||||||
|
// across renders should trigger the snap-to-bottom (i.e., the user
|
||||||
|
// just submitted something new).
|
||||||
|
const lastPendingCountRef = useRef(pending.length);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pending.length > lastPendingCountRef.current) {
|
if (pending.length > lastPendingCountRef.current) {
|
||||||
virtuosoRef.current?.scrollToIndex({
|
virtuosoRef.current?.scrollToIndex({
|
||||||
|
|||||||
Reference in New Issue
Block a user