Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/old-cities-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixes issue that caused threads to sometimes not scroll when sending messages
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const ThreadMessageList = ({ mainMessage, shouldJumpToBottom, setShouldJumpToBot

const virtualizerRef = useRef<VirtualizerHandle | null>(null);
const isAtBottom = useRef<boolean | null>(null);
const prevItemsLengthRef = useRef(0);

const { keepAtBottomRef, setKeepAtBottom } = useKeepAtBottom(isAtBottom);
const messagesLength = messages.length;
Expand Down Expand Up @@ -109,6 +110,7 @@ const ThreadMessageList = ({ mainMessage, shouldJumpToBottom, setShouldJumpToBot

useEffect(() => {
lastThreadJumpKeyRef.current = undefined;
prevItemsLengthRef.current = 0;
}, [mainMessage._id]);

useEffect(() => {
Expand All @@ -120,15 +122,31 @@ const ThreadMessageList = ({ mainMessage, shouldJumpToBottom, setShouldJumpToBot
setShouldJumpToBottom(false);
return;
}

// Scroll to bottom when current user's optimistic (temp) message is appended.
// Fires before server confirmation, giving immediate scroll feedback.
Comment thread
MartinSchoeler marked this conversation as resolved.
const prev = prevItemsLengthRef.current;
prevItemsLengthRef.current = items.length;
if (items.length > prev && uid) {
const lastItem = items.at(-1);
if (lastItem?.temp && lastItem.u._id === uid) {
setShouldJumpToBottom(true);
}
}

if (isAtBottom.current === true && lastScrollSizeRef.current !== handle?.scrollSize) {
lastScrollSizeRef.current = handle?.scrollSize ?? 0;
setShouldJumpToBottom(true);
}
if (shouldJumpToBottom) {
// Optimistically mark as at-bottom before the scroll executes (rAF).
// This ensures the ResizeObserver in useKeepAtBottom re-scrolls if
// quote/attachment content grows between now and when Virtua fires the scroll.
isAtBottom.current = true;
handle.scrollToIndex(items.length, { align: 'end' });
setShouldJumpToBottom(false);
}
}, [loading, items.length, msgJumpParam, threadMsgTargetIndex, shouldJumpToBottom, setShouldJumpToBottom]);
}, [items, loading, msgJumpParam, threadMsgTargetIndex, shouldJumpToBottom, setShouldJumpToBottom, uid]);

useEffect(() => {
if (threadMsgTargetIndex < 0 || !msgJumpParam) {
Expand Down
Loading