Skip to content

Commit 3d089e3

Browse files
chrisallogit-babel
andauthored
[CLNP-6698] resetWithStartingPoint not defined error (#1332)
Fixes [CLNP-6698](https://sendbird.atlassian.net/browse/CLNP-6698) ### Changelogs - Fixed a bug that `GroupChannelProvider` with `startingPoint` throws an error ### Checklist Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If unsure, ask the members. This is a reminder of what we look for before merging your code. - [x] **All tests pass locally with my changes** - [ ] **I have added tests that prove my fix is effective or that my feature works** - [ ] **Public components / utils / props are appropriately exported** - [ ] I have added necessary documentation (if appropriate) [CLNP-6698]: https://sendbird.atlassian.net/browse/CLNP-6698?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: junyoung.lim <junyoung.lim@sendbird.com>
1 parent 244425a commit 3d089e3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/modules/GroupChannel/context/GroupChannelProvider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ const GroupChannelManager :React.FC<React.PropsWithChildren<GroupChannelProvider
248248

249249
// Starting point handling
250250
useEffect(() => {
251-
if (typeof startingPoint === 'number') {
251+
if (typeof startingPoint === 'number' && messageDataSource.initialized) {
252252
actions.scrollToMessage(startingPoint, 0, false, false);
253253
}
254-
}, [startingPoint]);
254+
}, [messageDataSource.initialized, startingPoint]);
255255

256256
// Animated message handling
257257
useEffect(() => {

src/modules/GroupChannel/context/__tests__/useGroupChannel.spec.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ describe('useGroupChannel', () => {
304304
const mockResetWithStartingPoint = jest.fn().mockResolvedValue(undefined);
305305
const mockStore = createMockStore({
306306
messages: [],
307+
initialized: true,
307308
scrollRef: {
308309
current: document.createElement('div'),
309310
},

src/modules/GroupChannel/context/hooks/useGroupChannel.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const useGroupChannel = () => {
115115
const topOffset = getMessageTopOffset(message.createdAt);
116116
if (topOffset) state.scrollPubSub.publish('scroll', { top: topOffset, animated: scrollAnimated });
117117
if (messageFocusAnimated ?? true) setAnimatedMessageId(messageId);
118-
} else {
118+
} else if (state.initialized) {
119119
await state.resetWithStartingPoint(createdAt);
120120
setTimeout(() => {
121121
const topOffset = getMessageTopOffset(createdAt);
@@ -130,7 +130,12 @@ export const useGroupChannel = () => {
130130
});
131131
}
132132
clickHandler.activate();
133-
}, [setAnimatedMessageId, state.scrollRef.current, state.messages?.map(it => it?.messageId)]);
133+
}, [
134+
setAnimatedMessageId,
135+
state.initialized,
136+
state.scrollRef.current,
137+
state.messages?.map(it => it?.messageId),
138+
]);
134139

135140
const toggleReaction = useCallback((message: SendableMessageType, emojiKey: string, isReacted: boolean) => {
136141
if (!state.currentChannel) return;

0 commit comments

Comments
 (0)