fix(chat): let the timeline rail reach the last turn while it is unmounted
Both scrollToTurnId and scrollToMessageId hard-returned false when the target was the trailing (last) turn and its element was not mounted, so clicking the rail's last item in a long scrolled-up session did nothing. The trailing entry is a regular list row at the end of the data — scroll to its index the same way history targets are reached.
This commit is contained in:
@@ -1494,8 +1494,11 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
return container.querySelector(`[data-message-id="${messageId}"]`);
|
return container.querySelector(`[data-message-id="${messageId}"]`);
|
||||||
}, [resolveScrollContainer]);
|
}, [resolveScrollContainer]);
|
||||||
|
|
||||||
|
// Accepts any index the list renders, the trailing streaming entry
|
||||||
|
// included — it lives at historyEntries.length and is a legitimate
|
||||||
|
// navigation target (the timeline rail's last item).
|
||||||
const scrollHistoryIndexIntoView = React.useCallback((index: number) => {
|
const scrollHistoryIndexIntoView = React.useCallback((index: number) => {
|
||||||
if (index < 0 || index >= historyEntries.length) {
|
if (index < 0 || index >= allEntries.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1510,7 +1513,7 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
// path in scrollMessageElementIntoView.
|
// path in scrollMessageElementIntoView.
|
||||||
void list.scrollToIndex({ index, animated: false, viewPosition: 0 });
|
void list.scrollToIndex({ index, animated: false, viewPosition: 0 });
|
||||||
return true;
|
return true;
|
||||||
}, [historyEntries.length]);
|
}, [allEntries.length]);
|
||||||
|
|
||||||
const scrollMessageElementIntoView = React.useCallback((messageId: string, behavior: ScrollBehavior = 'auto') => {
|
const scrollMessageElementIntoView = React.useCallback((messageId: string, behavior: ScrollBehavior = 'auto') => {
|
||||||
const container = resolveScrollContainer();
|
const container = resolveScrollContainer();
|
||||||
@@ -1553,10 +1556,6 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetIsTail = trailingStreamingEntry !== undefined && index >= historyEntries.length;
|
|
||||||
if (targetIsTail) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return scrollHistoryIndexIntoView(index);
|
return scrollHistoryIndexIntoView(index);
|
||||||
},
|
},
|
||||||
@@ -1569,11 +1568,7 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return scrollMessageElementIntoView(messageId, behavior)
|
return scrollMessageElementIntoView(messageId, behavior)
|
||||||
|| (
|
|| scrollHistoryIndexIntoView(index);
|
||||||
trailingStreamingEntry !== undefined && index >= historyEntries.length
|
|
||||||
? false
|
|
||||||
: scrollHistoryIndexIntoView(index)
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
holdViewportAnchor: (anchor) => {
|
holdViewportAnchor: (anchor) => {
|
||||||
@@ -1716,7 +1711,7 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
return () => {
|
return () => {
|
||||||
objectRef.current = null;
|
objectRef.current = null;
|
||||||
};
|
};
|
||||||
}, [findMessageElement, historyEntries.length, messageIndexMap, resolveScrollContainer, scrollHistoryIndexIntoView, scrollMessageElementIntoView, trailingStreamingEntry, turnIndexMap, ref]);
|
}, [findMessageElement, historyEntries.length, messageIndexMap, resolveScrollContainer, scrollHistoryIndexIntoView, scrollMessageElementIntoView, turnIndexMap, ref]);
|
||||||
|
|
||||||
const anchoredEndSpace = React.useMemo<TimelineAnchoredEndSpace | undefined>(() => {
|
const anchoredEndSpace = React.useMemo<TimelineAnchoredEndSpace | undefined>(() => {
|
||||||
const resolved = resolveChatListAnchoredEndSpace(
|
const resolved = resolveChatListAnchoredEndSpace(
|
||||||
|
|||||||
Reference in New Issue
Block a user