Skip to content

Commit

Permalink
fix: rerender chat when opened with existing messages
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 authored Mar 18, 2024
1 parent c9957ee commit 54faa73
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/roomkit-react/src/Prebuilt/components/Chat/ChatBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export const ChatBody = React.forwardRef<VariableSizeList, { scrollToBottom: (co
}, [blacklistedMessageIDs, messages]);

const vanillaStore = useHMSVanillaStore();
const rerenderOnFirstMount = useRef(false);

useEffect(() => {
const unsubscribe = vanillaStore.subscribe(() => {
Expand All @@ -426,6 +427,15 @@ export const ChatBody = React.forwardRef<VariableSizeList, { scrollToBottom: (co
return unsubscribe;
}, [vanillaStore, listRef, scrollToBottom]);

useEffect(() => {
// @ts-ignore
if (filteredMessages.length > 0 && listRef?.current && !rerenderOnFirstMount.current) {
rerenderOnFirstMount.current = true;
// @ts-ignore
listRef.current.resetAfterIndex(0);
}
}, [listRef, filteredMessages]);

return filteredMessages.length === 0 ? (
<EmptyChat />
) : (
Expand Down

0 comments on commit 54faa73

Please sign in to comment.