Skip to content

Commit 0c5fa0f

Browse files
authored
[CLNP-7360]Multiple Chat Windows cause unexpected behavior (#1358)
[fix]: Multiple Chat Windows cause unexpected behavior PR description - initialState안에 xxxRef들이 Object로 되어 있어서 여러 Provider 인스턴스가 생성될 때 동일한 객체 참조를 공유하는 문제가 있었습니다. 함수로 변경함으로써 각 Provider 인스턴스마다 새로운 초기 상태 객체를 생성하도록 하여 상태 격리 문제를 해결했습니다. Fixes [CLNP-7360](https://sendbird.atlassian.net/browse/CLNP-7360) ### Changelogs - Fixed a bug Where Multiple Chat Windows cause unexpected behavior ### 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) ## External Contributions This project is not yet set up to accept pull requests from external contributors. If you have a pull request that you believe should be accepted, please contact the Developer Relations team <developer-advocates@sendbird.com> with details and we'll evaluate if we can set up a [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement) to allow for the contribution. [CLNP-7360]: https://sendbird.atlassian.net/browse/CLNP-7360?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent cd03158 commit 0c5fa0f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/modules/GroupChannel/context/GroupChannelProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import useSendbird from '../../../lib/Sendbird/context/hooks/useSendbird';
3333
import useDeepCompareEffect from '../../../hooks/useDeepCompareEffect';
3434
import { deleteNullish } from '../../../utils/utils';
3535

36-
const initialState = {
36+
const initialState = () => ({
3737
currentChannel: null,
3838
channelUrl: '',
3939
fetchChannelError: null,
@@ -60,12 +60,12 @@ const initialState = {
6060
disableMarkAsRead: false,
6161
scrollBehavior: 'auto',
6262
scrollPubSub: null,
63-
} as GroupChannelState;
63+
} as GroupChannelState);
6464

6565
export const GroupChannelContext = createContext<ReturnType<typeof createStore<GroupChannelState>> | null>(null);
6666

6767
const createGroupChannelStore = (props?: Partial<GroupChannelState>) => createStore({
68-
...initialState,
68+
...initialState(),
6969
...props,
7070
});
7171

@@ -378,7 +378,7 @@ const GroupChannelProvider: React.FC<GroupChannelProviderProps> = (props) => {
378378
* @returns {ReturnType<typeof createStore<GroupChannelState>>}
379379
*/
380380
const useGroupChannelStore = () => {
381-
return useStore(GroupChannelContext, state => state, initialState);
381+
return useStore(GroupChannelContext, state => state, initialState());
382382
};
383383

384384
// Keep this function for backward compatibility.

src/modules/GroupChannelList/context/GroupChannelListProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const GroupChannelListContext = React.createContext<ReturnType<typeof cre
6262
export interface GroupChannelListState extends GroupChannelListContextType {
6363
}
6464

65-
const initialState: GroupChannelListState = {
65+
const initialState = () => ({
6666
className: '',
6767
selectedChannelUrl: '',
6868
disableAutoSelect: false,
@@ -82,13 +82,13 @@ const initialState: GroupChannelListState = {
8282
refresh: null,
8383
loadMore: null,
8484
scrollRef: { current: null },
85-
};
85+
} as GroupChannelListState);
8686

8787
/**
8888
* @returns {ReturnType<typeof createStore<GroupChannelListState>>}
8989
*/
9090
export const useGroupChannelListStore = () => {
91-
return useStore(GroupChannelListContext, state => state, initialState);
91+
return useStore(GroupChannelListContext, state => state, initialState());
9292
};
9393

9494
export const GroupChannelListManager: React.FC<GroupChannelListProviderProps> = ({
@@ -229,7 +229,7 @@ export const GroupChannelListManager: React.FC<GroupChannelListProviderProps> =
229229
};
230230

231231
const createGroupChannelListStore = (props?: Partial<GroupChannelListState>) => createStore({
232-
...initialState,
232+
...initialState(),
233233
...props,
234234
});
235235

src/modules/Thread/context/ThreadProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface ThreadState extends ThreadProviderProps {
5959
nicknamesMap: Map<string, string>;
6060
}
6161

62-
const initialState: ThreadState = {
62+
const initialState = () => ({
6363
channelUrl: '',
6464
message: null,
6565
onHeaderActionClick: undefined,
@@ -86,12 +86,12 @@ const initialState: ThreadState = {
8686
currentUserId: '',
8787
typingMembers: [],
8888
nicknamesMap: null,
89-
};
89+
} as ThreadState);
9090

9191
export const ThreadContext = React.createContext<ReturnType<typeof createStore<ThreadState>> | null>(null);
9292

9393
const createThreadStore = (props?: Partial<ThreadState>) => createStore({
94-
...initialState,
94+
...initialState(),
9595
...props,
9696
});
9797

@@ -248,5 +248,5 @@ export const useThreadContext = () => {
248248
};
249249

250250
const useThreadStore = () => {
251-
return useStore(ThreadContext, state => state, initialState);
251+
return useStore(ThreadContext, state => state, initialState());
252252
};

0 commit comments

Comments
 (0)