Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,14 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {

const [autoscrollToRecent, setAutoscrollToRecent] = useState(false);

const minIndexForVisible = Math.min(1, processedMessageList.length);

const maintainVisibleContentPosition = useMemo(
() => ({
autoscrollToTopThreshold: autoscrollToRecent ? 10 : undefined,
minIndexForVisible: 1,
minIndexForVisible,
}),
[autoscrollToRecent],
[autoscrollToRecent, minIndexForVisible],
);

/**
Expand Down Expand Up @@ -620,7 +622,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
}, [threadList, messageListLengthAfterUpdate, topMessageAfterUpdate?.id]);

useEffect(() => {
if (!rawMessageList.length) {
if (!processedMessageList.length) {
return;
}
if (threadList) {
Expand All @@ -637,7 +639,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
}
const latestNonCurrentMessageBeforeUpdate = latestNonCurrentMessageBeforeUpdateRef.current;
latestNonCurrentMessageBeforeUpdateRef.current = undefined;
const latestCurrentMessageAfterUpdate = rawMessageList[rawMessageList.length - 1];
const latestCurrentMessageAfterUpdate = processedMessageList[0];
if (!latestCurrentMessageAfterUpdate) {
setAutoscrollToRecent(true);
return;
Expand All @@ -662,7 +664,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [channel, rawMessageList, threadList]);
}, [channel, processedMessageList, threadList]);

const goToMessage = useStableCallback(async (messageId: string) => {
const indexOfParentInMessageList = processedMessageList.findIndex(
Expand Down