Skip to content

Commit cc39913

Browse files
committed
fix: avoid breaking change for getDefaultItems methods
1 parent 97a1379 commit cc39913

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

package/src/hooks/actions/useChannelActionItems.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ import { useChannelMembershipState } from '../useChannelMembershipState';
2222
import { useIsDirectChat } from '../useIsDirectChat';
2323
import { useStateStore } from '../useStateStore';
2424

25+
// Lazily resolved to avoid a static import cycle with defaultComponents.ts
26+
// (defaultComponents → ChannelDetails*/ChannelPreview* → this file). Statically
27+
// importing defaultIcons corrupts module-init order; require it at call time
28+
// instead. Same pattern as ComponentsContext's getDefaults().
29+
let cachedDefaultIcons: IconsMap | undefined;
30+
const getDefaultIcons = (): IconsMap => {
31+
if (!cachedDefaultIcons) {
32+
cachedDefaultIcons = (
33+
require('../../contexts/componentsContext/defaultComponents') as { defaultIcons: IconsMap }
34+
).defaultIcons;
35+
}
36+
return cachedDefaultIcons;
37+
};
38+
2539
export type ChannelActionItem = ActionItem<
2640
'mute' | 'muteUser' | 'block' | 'leave' | 'deleteChannel' | 'pin' | string
2741
> & {
@@ -75,7 +89,7 @@ export type ChannelActionItemsParams = {
7589
};
7690

7791
export type BuildDefaultChannelActionItems = (
78-
channelActionItemsParams: ChannelActionItemsParams,
92+
channelActionItemsParams: Omit<ChannelActionItemsParams, 'icons'> & { icons?: IconsMap },
7993
) => ChannelActionItem[];
8094

8195
const ChannelActionsIcon = ({
@@ -106,7 +120,7 @@ export const buildDefaultChannelActionItems: BuildDefaultChannelActionItems = (
106120
unpin,
107121
},
108122
channelMuteActive,
109-
icons,
123+
icons = getDefaultIcons(),
110124
isBlocked,
111125
isDirectChat,
112126
isPinned,

package/src/hooks/actions/useChannelMemberActionItems.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ import { IconProps } from '../../icons';
1616
import { useChannelOwnCapabilities } from '../useChannelOwnCapabilities';
1717
import { useStateStore } from '../useStateStore';
1818

19+
// Lazily resolved to avoid a static import cycle with defaultComponents.ts
20+
// (defaultComponents → ChannelDetails*/ChannelPreview* → this file). Statically
21+
// importing defaultIcons corrupts module-init order; require it at call time
22+
// instead. Same pattern as ComponentsContext's getDefaults().
23+
let cachedDefaultIcons: IconsMap | undefined;
24+
const getDefaultIcons = (): IconsMap => {
25+
if (!cachedDefaultIcons) {
26+
cachedDefaultIcons = (
27+
require('../../contexts/componentsContext/defaultComponents') as { defaultIcons: IconsMap }
28+
).defaultIcons;
29+
}
30+
return cachedDefaultIcons;
31+
};
32+
1933
export type ChannelMemberActionItem = ActionItem<'muteUser' | 'block' | string>;
2034

2135
export type ChannelMemberActionItemsParams = {
@@ -32,7 +46,9 @@ export type ChannelMemberActionItemsParams = {
3246
};
3347

3448
export type BuildDefaultChannelMemberActionItems = (
35-
channelMemberActionItemsParams: ChannelMemberActionItemsParams,
49+
channelMemberActionItemsParams: Omit<ChannelMemberActionItemsParams, 'icons'> & {
50+
icons?: IconsMap;
51+
},
3652
) => ChannelMemberActionItem[];
3753

3854
const ChannelMemberActionsIcon = ({
@@ -51,7 +67,7 @@ export const buildDefaultChannelMemberActionItems: BuildDefaultChannelMemberActi
5167
) => {
5268
const {
5369
channelActions: { removeMembers },
54-
icons,
70+
icons = getDefaultIcons(),
5571
isBlocked,
5672
isCurrentUser,
5773
member,

0 commit comments

Comments
 (0)