diff --git a/src/modules/GroupChannel/context/GroupChannelProvider.tsx b/src/modules/GroupChannel/context/GroupChannelProvider.tsx index 5802faa8d..cfaf4514c 100644 --- a/src/modules/GroupChannel/context/GroupChannelProvider.tsx +++ b/src/modules/GroupChannel/context/GroupChannelProvider.tsx @@ -248,10 +248,10 @@ const GroupChannelManager :React.FC { - if (typeof startingPoint === 'number') { + if (typeof startingPoint === 'number' && messageDataSource.initialized) { actions.scrollToMessage(startingPoint, 0, false, false); } - }, [startingPoint]); + }, [messageDataSource.initialized, startingPoint]); // Animated message handling useEffect(() => { diff --git a/src/modules/GroupChannel/context/__tests__/useGroupChannel.spec.tsx b/src/modules/GroupChannel/context/__tests__/useGroupChannel.spec.tsx index 234c8523f..a5de60482 100644 --- a/src/modules/GroupChannel/context/__tests__/useGroupChannel.spec.tsx +++ b/src/modules/GroupChannel/context/__tests__/useGroupChannel.spec.tsx @@ -304,6 +304,7 @@ describe('useGroupChannel', () => { const mockResetWithStartingPoint = jest.fn().mockResolvedValue(undefined); const mockStore = createMockStore({ messages: [], + initialized: true, scrollRef: { current: document.createElement('div'), }, diff --git a/src/modules/GroupChannel/context/hooks/useGroupChannel.ts b/src/modules/GroupChannel/context/hooks/useGroupChannel.ts index 591507658..f28819afd 100644 --- a/src/modules/GroupChannel/context/hooks/useGroupChannel.ts +++ b/src/modules/GroupChannel/context/hooks/useGroupChannel.ts @@ -115,7 +115,7 @@ export const useGroupChannel = () => { const topOffset = getMessageTopOffset(message.createdAt); if (topOffset) state.scrollPubSub.publish('scroll', { top: topOffset, animated: scrollAnimated }); if (messageFocusAnimated ?? true) setAnimatedMessageId(messageId); - } else { + } else if (state.initialized) { await state.resetWithStartingPoint(createdAt); setTimeout(() => { const topOffset = getMessageTopOffset(createdAt); @@ -130,7 +130,12 @@ export const useGroupChannel = () => { }); } clickHandler.activate(); - }, [setAnimatedMessageId, state.scrollRef.current, state.messages?.map(it => it?.messageId)]); + }, [ + setAnimatedMessageId, + state.initialized, + state.scrollRef.current, + state.messages?.map(it => it?.messageId), + ]); const toggleReaction = useCallback((message: SendableMessageType, emojiKey: string, isReacted: boolean) => { if (!state.currentChannel) return;