Skip to content

Commit aca9fe2

Browse files
authored
Merge pull request #1738 from GetStream/fix-rapid-jump-crash
fix: avoid race condition crash in jumping
2 parents 503bb53 + 488a1b1 commit aca9fe2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/Channel/Channel.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ const ChannelInner = <
524524
return queryResponse.messages.length;
525525
};
526526

527+
const clearHighlightedMessageTimeoutId = useRef<ReturnType<typeof setTimeout> | null>(null);
528+
527529
const jumpToMessage = async (messageId: string, messageLimit = 100) => {
528530
dispatch({ loadingMore: true, type: 'setLoadingMore' });
529531
await channel.state.loadMessageIntoState(messageId, undefined, messageLimit);
@@ -542,7 +544,12 @@ const ChannelInner = <
542544
type: 'jumpToMessageFinished',
543545
});
544546

545-
setTimeout(() => {
547+
if (clearHighlightedMessageTimeoutId.current) {
548+
clearTimeout(clearHighlightedMessageTimeoutId.current);
549+
}
550+
551+
clearHighlightedMessageTimeoutId.current = setTimeout(() => {
552+
clearHighlightedMessageTimeoutId.current = null;
546553
dispatch({ type: 'clearHighlightedMessage' });
547554
}, 500);
548555
};

0 commit comments

Comments
 (0)