Skip to content

Commit e976fe3

Browse files
committed
Revert "Merge pull request #802 from GetStream/active-channels-perf-fix"
This reverts commit bfb9f66, reversing changes made to eab95f0.
1 parent 9e29c2b commit e976fe3

File tree

9 files changed

+25
-72
lines changed

9 files changed

+25
-72
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ const ChannelWithContext = <
523523
supportedReactions = reactionData,
524524
t,
525525
thread: threadProps,
526-
threadList,
527526
threadMessages,
528527
threadRepliesEnabled: threadRepliesEnabledProp,
529528
threadReply,
@@ -1563,7 +1562,6 @@ const ChannelWithContext = <
15631562
setTargetedMessage,
15641563
StickyHeader,
15651564
targetedMessage,
1566-
threadList,
15671565
watcherCount,
15681566
watchers,
15691567
});

package/src/components/Channel/hooks/useCreateChannelContext.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const useCreateChannelContext = <
4747
setTargetedMessage,
4848
StickyHeader,
4949
targetedMessage,
50-
threadList,
5150
typingEventsEnabled,
5251
watcherCount,
5352
watchers,
@@ -88,7 +87,6 @@ export const useCreateChannelContext = <
8887
setTargetedMessage,
8988
StickyHeader,
9089
targetedMessage,
91-
threadList,
9290
typingEventsEnabled,
9391
watcherCount,
9492
watchers,
@@ -104,7 +102,6 @@ export const useCreateChannelContext = <
104102
readUsersLength,
105103
readUsersLastReads,
106104
targetedMessage,
107-
threadList,
108105
typingEventsEnabled,
109106
watcherCount,
110107
],

package/src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
22

33
import { MAX_QUERY_CHANNELS_LIMIT } from '../utils';
44

5-
import { useActiveChannelsRefContext } from '../../../contexts/activeChannelsRefContext/ActiveChannelsRefContext';
5+
import { useActiveChannels } from '../../../contexts/channelsStateContext/useActiveChannels';
66
import { useChatContext } from '../../../contexts/chatContext/ChatContext';
77

88
import type { Channel, ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';
@@ -51,7 +51,7 @@ export const usePaginatedChannels = <
5151
sort = {},
5252
}: Parameters<Ch, Co, Us>) => {
5353
const { client } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
54-
const activeChannels = useActiveChannelsRefContext();
54+
const activeChannels = useActiveChannels();
5555

5656
const [channels, setChannels] = useState<Channel<At, Ch, Co, Ev, Me, Re, Us>[]>([]);
5757
const [error, setError] = useState(false);

package/src/components/MessageList/MessageList.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ export const MessageList = <
950950
setTargetedMessage,
951951
StickyHeader,
952952
targetedMessage,
953-
threadList,
954953
typingEventsEnabled,
955954
} = useChannelContext<At, Ch, Co, Ev, Me, Re, Us>();
956955
const { client } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
@@ -974,13 +973,6 @@ export const MessageList = <
974973
const { loadMoreThread, thread } = useThreadContext<At, Ch, Co, Ev, Me, Re, Us>();
975974
const { t, tDateTimeParser } = useTranslationContext();
976975

977-
// This needs to happen here because there is already a threadList prop added to the MessageList
978-
if (thread?.id && !threadList) {
979-
throw new Error(
980-
'Please add a threadList prop to your Channel component when rendering a thread list. Check our Channel documentation for more info: https://getstream.io/chat/docs/sdk/reactnative/core-components/channel/#threadlist',
981-
);
982-
}
983-
984976
return (
985977
<MessageListWithContext
986978
{...{

package/src/contexts/activeChannelsRefContext/ActiveChannelsRefContext.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

package/src/contexts/channelContext/ChannelContext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export type ChannelContextValue<
181181
* You will see a highlighted background for targetted message, when opened.
182182
*/
183183
targetedMessage?: string;
184-
threadList?: boolean;
185184
watcherCount?: ChannelState<At, Ch, Co, Ev, Me, Re, Us>['watcher_count'];
186185
} & ChannelConfig;
187186

package/src/contexts/channelsStateContext/ChannelsStateContext.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import React, {
2-
ReactNode,
3-
useCallback,
4-
useContext,
5-
useEffect,
6-
useMemo,
7-
useReducer,
8-
useRef,
9-
} from 'react';
10-
11-
import { ActiveChannelsProvider } from '../activeChannelsRefContext/ActiveChannelsRefContext';
1+
import React, { ReactNode, useCallback, useContext, useMemo, useReducer } from 'react';
122

133
import type { ChannelContextValue } from '../channelContext/ChannelContext';
144
import type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext';
@@ -229,15 +219,9 @@ export const ChannelsStateProvider = <
229219
[state],
230220
);
231221

232-
const activeChannelsRef = useRef(Object.keys(state));
233-
234-
useEffect(() => {
235-
activeChannelsRef.current = Object.keys(state);
236-
}, [state]);
237-
238222
return (
239223
<ChannelsStateContext.Provider value={value as unknown as ChannelsStateContextValue}>
240-
<ActiveChannelsProvider value={activeChannelsRef}>{children}</ActiveChannelsProvider>
224+
{children}
241225
</ChannelsStateContext.Provider>
242226
);
243227
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
import { useChannelsStateContext } from './ChannelsStateContext';
4+
5+
/*
6+
This needs to be a reference because the functions using it are not memoized (because they change too much even if you do
7+
due to the dependencies they have) and they're called on connection state changes on the client which are subscribed on
8+
mount with an useEffect so they're always getting only the first function reference which uses the old value of this
9+
active channels array (would always be empty). Using a ref solves this problem cause then it will always be updated to
10+
the latest one.
11+
*/
12+
export const useActiveChannels = () => {
13+
const { state } = useChannelsStateContext();
14+
const activeChannelsRef = useRef(Object.keys(state));
15+
16+
useEffect(() => {
17+
activeChannelsRef.current = Object.keys(state);
18+
}, [state]);
19+
20+
return activeChannelsRef;
21+
};

package/src/contexts/channelsStateContext/useChannelState.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ type StateManagerParams<
3333
key: Key;
3434
};
3535

36-
/*
37-
This hook takes care of creating a useState-like interface which can be used later to call
38-
updates to the ChannelsStateContext reducer. It receives the cid and key which it wants to update
39-
and perform the state updates. Also supports a initialState.
40-
*/
4136
function useStateManager<
4237
Key extends Keys,
4338
At extends UnknownType = DefaultAttachmentType,

0 commit comments

Comments
 (0)