Skip to content

Commit 8ab573c

Browse files
committed
fix: prevent overriding active channel UI on ChannelList pagination error
1 parent 76228d8 commit 8ab573c

3 files changed

Lines changed: 56 additions & 4 deletions

File tree

src/components/Channel/Channel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ const UnMemoizedChannel = (props: PropsWithChildren<ChannelProps>) => {
192192
);
193193
}
194194

195-
if (channelsQueryState.error && LoadingErrorIndicator) {
195+
if (channelsQueryState.error && !channel && LoadingErrorIndicator) {
196196
return (
197197
<ChannelContainer>
198198
<LoadingErrorIndicator error={channelsQueryState.error} />
199199
</ChannelContainer>
200200
);
201201
}
202202

203-
if (channelsQueryState.error) {
203+
if (channelsQueryState.error && !channel) {
204204
return <ChannelContainer />;
205205
}
206206

src/components/Channel/__tests__/Channel.test.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ describe('Channel', () => {
380380
await waitFor(() => expect(asFragment()).toMatchSnapshot());
381381
});
382382

383-
it('should render empty channel container if channels query failed', async () => {
383+
it('should render empty channel container if channels query failed and no channel is available', async () => {
384384
const childrenContent = 'Channel children';
385385
const { asFragment } = render(
386386
<ChatProvider
@@ -399,6 +399,58 @@ describe('Channel', () => {
399399
await waitFor(() => expect(asFragment()).toMatchSnapshot());
400400
});
401401

402+
it('should render channel content if channels query failed but channel is available', async () => {
403+
const childrenContent = 'Channel children';
404+
await channel.watch();
405+
render(
406+
<ChatProvider
407+
value={fromPartial<ChatContextValue>({
408+
channelsQueryState: {
409+
error: new Error('pagination failed'),
410+
queryInProgress: null,
411+
setError: vi.fn(),
412+
setQueryInProgress: vi.fn(),
413+
},
414+
client: chatClient,
415+
searchController: new SearchController(),
416+
})}
417+
>
418+
<Channel channel={channel}>{childrenContent}</Channel>
419+
</ChatProvider>,
420+
);
421+
await waitFor(() => expect(screen.getByText(childrenContent)).toBeInTheDocument());
422+
});
423+
424+
it('should render channel content if channels query failed and channel is available even if LoadingErrorIndicator is provided', async () => {
425+
const errMsg = 'Channels query failed';
426+
const childrenContent = 'Channel children';
427+
await channel.watch();
428+
render(
429+
<ChatProvider
430+
value={fromPartial<ChatContextValue>({
431+
channelsQueryState: {
432+
error: new Error(errMsg),
433+
queryInProgress: null,
434+
setError: vi.fn(),
435+
setQueryInProgress: vi.fn(),
436+
},
437+
client: chatClient,
438+
searchController: new SearchController(),
439+
})}
440+
>
441+
<WithComponents
442+
overrides={{
443+
LoadingErrorIndicator: ({ error }) => <div>{error.message}</div>,
444+
}}
445+
>
446+
<Channel channel={channel}>{childrenContent}</Channel>
447+
</WithComponents>
448+
</ChatProvider>,
449+
);
450+
await waitFor(() => expect(screen.getByText(childrenContent)).toBeInTheDocument());
451+
expect(screen.queryByText(errMsg)).not.toBeInTheDocument();
452+
});
453+
402454
it('should render provided loading indicator if channels query is in progress', async () => {
403455
const childrenContent = 'Channel children';
404456
const loadingText = 'Loading channels';

src/components/Channel/__tests__/__snapshots__/Channel.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ exports[`Channel > should render empty channel container if channel does not hav
5050
</DocumentFragment>
5151
`;
5252

53-
exports[`Channel > should render empty channel container if channels query failed 1`] = `
53+
exports[`Channel > should render empty channel container if channels query failed and no channel is available 1`] = `
5454
<DocumentFragment>
5555
<div
5656
class="str-chat str-chat__channel"

0 commit comments

Comments
 (0)