Skip to content

Commit 534c503

Browse files
authored
fix: v15 regressions found in side-by-side QA (#3364)
1 parent b2a8ded commit 534c503

29 files changed

Lines changed: 663 additions & 90 deletions

‎examples/ai-chatbot/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"next": "^16.2.4",
1919
"react": "^19.2.6",
2020
"react-dom": "^19.2.6",
21-
"stream-chat": "10.0.0-rc.32",
21+
"stream-chat": "10.0.0-rc.34",
2222
"stream-chat-react": "workspace:^"
2323
},
2424
"devDependencies": {

‎examples/cookbook/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react": "^19.2.6",
2020
"react-dom": "^19.2.6",
2121
"react-leaflet": "^5.0.0",
22-
"stream-chat": "10.0.0-rc.32",
22+
"stream-chat": "10.0.0-rc.34",
2323
"stream-chat-react": "workspace:^"
2424
},
2525
"devDependencies": {

‎examples/tutorial/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"emoji-mart": "^5.6.0",
1717
"react": "^19.2.6",
1818
"react-dom": "^19.2.6",
19-
"stream-chat": "10.0.0-rc.32",
19+
"stream-chat": "10.0.0-rc.34",
2020
"stream-chat-react": "workspace:^"
2121
},
2222
"devDependencies": {

‎examples/vite/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"modern-normalize": "^3.0.1",
1919
"react": "^19.2.6",
2020
"react-dom": "^19.2.6",
21-
"stream-chat": "10.0.0-rc.32",
21+
"stream-chat": "10.0.0-rc.34",
2222
"stream-chat-react": "workspace:^"
2323
},
2424
"devDependencies": {

‎examples/vite/src/ChatLayout/SwitchableChannelNavigation.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,20 @@ const ChannelListSwitcher = ({
171171
// interval), so render both here, in a section above the list. `intervalViews` emits regardless of
172172
// which interval is active, and the selector below only wakes when logicalHead/logicalTail change
173173
// (not the `head` field), so this stays reactive even while the list shows a different window.
174+
// With no page loaded (e.g. every channel was hidden, then shown again) a logical interval is itself
175+
// the active one, so `ChannelList` already shows its channels: those are skipped here.
174176
const sideloadedSelector = (state: PaginatorIntervalViews<Channel>) => ({
175177
head: state.logicalHead,
176178
tail: state.logicalTail,
177179
});
180+
const listedItemsSelector = (state: { items?: Channel[] }) => ({ items: state.items });
178181
const SideloadedChannels = ({ paginator }: { paginator: ChannelPaginator }) => {
179182
const { head, tail } = useStateStore(paginator.intervalViews, sideloadedSelector);
183+
const { items } = useStateStore(paginator.state, listedItemsSelector);
180184
// Head items sort newer than the loaded window, tail items older — concatenated they are all the
181185
// out-of-order (sideloaded) channels, newest first.
182-
const channels = [...head, ...tail];
186+
const listed = new Set(items?.map((channel) => channel.cid));
187+
const channels = [...head, ...tail].filter((channel) => !listed.has(channel.cid));
183188
if (!channels.length) return null;
184189
return (
185190
<div className='app-sideloaded-channels'>

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"modern-normalize": "^3.0.1",
164164
"react": "^19.0.0 || ^18.0.0 || ^17.0.0",
165165
"react-dom": "^19.0.0 || ^18.0.0 || ^17.0.0",
166-
"stream-chat": "^10.0.0-rc.32"
166+
"stream-chat": "^10.0.0-rc.34"
167167
},
168168
"peerDependenciesMeta": {
169169
"@a2ui/react": {
@@ -246,7 +246,7 @@
246246
"react-dom": "^19.2.6",
247247
"sass": "^1.100.0",
248248
"semantic-release": "^25.0.3",
249-
"stream-chat": "10.0.0-rc.32",
249+
"stream-chat": "10.0.0-rc.34",
250250
"typescript": "^6.0.3",
251251
"typescript-eslint": "^8.59.4",
252252
"vite": "^8.1.3",

‎src/components/ChannelList/ChannelList.tsx‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ComponentProps, ComponentType } from 'react';
2-
import React, { useEffect, useRef } from 'react';
2+
import React, { useEffect, useMemo, useRef } from 'react';
33
import type { Channel, ChannelPaginator, ChannelPaginatorState } from 'stream-chat';
44

55
import { ChannelListItem } from '../ChannelListItem';
@@ -48,16 +48,20 @@ export type ChannelListProps = {
4848
loadMoreThresholdPx?: number;
4949
};
5050

51-
const channelPaginatorStateSelector = (state: ChannelPaginatorState) => ({
52-
// `items === undefined` means "never queried": the initial state, and where a paginator returns
53-
// when its data is discarded (e.g. `client.disconnectUser` resets every registered list). An
54-
// empty array is a loaded empty page and must not trigger a query. A failed first page leaves
55-
// `items` undefined too, but holds the error until a retry or a reset; with `throwErrors` set,
56-
// that error is all that keeps the list from querying again and again.
57-
awaitsFirstPage: state.items === undefined && !state.isLoading && !state.lastQueryError,
58-
firstPageLoadError: getFirstPageLoadError(state),
59-
lastQueryError: state.lastQueryError,
60-
});
51+
const createChannelPaginatorStateSelector =
52+
(paginator: ChannelPaginator) => (state: ChannelPaginatorState) => ({
53+
// No loaded page: the initial state, and where a paginator returns when its data is discarded
54+
// (e.g. `client.disconnectUser` resets every registered list). Not `items === undefined`: a
55+
// live event can route a channel into a list that was never queried, which defines `items`
56+
// without loading a page. A loaded empty page (also one set with `setItems`, e.g. a catch-all
57+
// list seeded so it never queries) must not trigger a query. A failed first page loads none
58+
// either, but holds the error until a retry or a reset; with `throwErrors` set, that error is
59+
// all that keeps the list from querying again and again.
60+
awaitsFirstPage:
61+
!paginator.hasLoadedPage && !state.isLoading && !state.lastQueryError,
62+
firstPageLoadError: getFirstPageLoadError(state),
63+
lastQueryError: state.lastQueryError,
64+
});
6165

6266
/**
6367
* Channel list driven by a single `ChannelPaginator`: it renders the paginator's state and drives
@@ -72,6 +76,10 @@ export const ChannelList = ({
7276
}: ChannelListProps) => {
7377
const { channelManager } = useChatContext();
7478
const { t } = useTranslationContext();
79+
const channelPaginatorStateSelector = useMemo(
80+
() => createChannelPaginatorStateSelector(paginator),
81+
[paginator],
82+
);
7583
const { awaitsFirstPage, firstPageLoadError, lastQueryError } = useStateStore(
7684
paginator.state,
7785
channelPaginatorStateSelector,
@@ -95,12 +103,12 @@ export const ChannelList = ({
95103
// Ref-counted, so `Chat` and other lists can register the same subscriptions.
96104
useEffect(() => channelManager.registerSubscriptions(), [channelManager]);
97105

98-
// Loads the first page, and again whenever the list returns to "never queried": the paginator
106+
// Loads the first page, and again whenever the list returns to "no page loaded": the paginator
99107
// outlives this component, so querying only on mount would leave a reset list permanently empty.
100-
// An initialized paginator has queried already; its pages arrive through that query or its
101-
// recovery, and a query from here would load the next page.
108+
// A paginator with a loaded page has queried already (or was seeded); its pages arrive through
109+
// that query or its recovery, and a query from here would load the next page.
102110
useEffect(() => {
103-
if (!awaitsFirstPage || paginator.isInitialized) return;
111+
if (!awaitsFirstPage) return;
104112
paginator.toTailDebounced();
105113
}, [awaitsFirstPage, paginator]);
106114

‎src/components/ChannelList/__tests__/ChannelList.test.tsx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,45 @@ describe('ChannelList', () => {
8282
expect(queryChannels).not.toHaveBeenCalled();
8383
});
8484

85+
// A live event can route a channel into a list that was never queried (e.g. a message makes a
86+
// channel unread before the "Unread" list was ever shown): `items` is then defined, but no page
87+
// was loaded, so the first query still has to run.
88+
it('queries the first page of a list that a live event reached first', async () => {
89+
const { client, queryChannels } = await setupClient();
90+
const paginator = new ChannelPaginator({ client, id: 'channels:a' });
91+
paginator.ingestItem(client.channel('messaging', 'ingested'));
92+
expect(paginator.items).toHaveLength(1);
93+
94+
renderList(client, paginator);
95+
96+
await waitFor(() => expect(queryChannels).toHaveBeenCalledTimes(1));
97+
});
98+
99+
it('queries the first page of a list that a live event reached and left again', async () => {
100+
const { client, queryChannels } = await setupClient();
101+
const paginator = new ChannelPaginator({ client, id: 'channels:a' });
102+
const channel = client.channel('messaging', 'ingested');
103+
paginator.ingestItem(channel);
104+
paginator.removeItem({ item: channel });
105+
expect(paginator.items).toEqual([]);
106+
107+
renderList(client, paginator);
108+
109+
await waitFor(() => expect(queryChannels).toHaveBeenCalledTimes(1));
110+
});
111+
112+
it('does not query a seeded list that a live event reached', async () => {
113+
const { client, queryChannels } = await setupClient();
114+
const paginator = new ChannelPaginator({ client, id: 'channels:a' });
115+
paginator.setItems({ isLastPage: true, valueOrFactory: [] });
116+
paginator.ingestItem(client.channel('messaging', 'ingested'));
117+
118+
renderList(client, paginator);
119+
120+
await waitFor(() => expect(paginator.items).toHaveLength(1));
121+
expect(queryChannels).not.toHaveBeenCalled();
122+
});
123+
85124
it('re-queries when the list data is discarded while it stays mounted', async () => {
86125
const { client, queryChannels } = await setupClient();
87126
const paginator = new ChannelPaginator({ client, id: 'channels:a' });

‎src/components/Dialog/service/DialogAnchor.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ export const DialogAnchor = ({
231231

232232
return (
233233
<DialogPortalEntry dialogId={id} dialogManagerId={dialogManagerId}>
234-
<FocusScope autoFocus={focus} contain={trapFocus} restoreFocus>
234+
{/* A closing dialog releases the trap, so an action that moves focus elsewhere as it closes the
235+
dialog (e.g. "Edit Message" focusing the composer) keeps it there. */}
236+
<FocusScope autoFocus={focus} contain={trapFocus && !isClosing} restoreFocus>
235237
<div
236238
{...anchorDivProps}
237239
aria-describedby={ariaDescribedBy}

‎src/components/InfiniteScrollPaginator/InfiniteScrollWithComponents.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ type PaginatorLike<TItem> = {
1212
hasMoreHead: boolean;
1313
hasMoreTail: boolean;
1414
state: StateStore<PaginatorState<TItem>>;
15+
/**
16+
* The item's identity in the paginator, used as the React key. Needed where `id` is not unique: a
17+
* channel's `id` is unique only within its type, so a channel paginator keys by `cid`.
18+
*/
19+
getItemId?: (item: TItem) => string;
1520
};
1621

1722
export type InfiniteScrollWithComponentsProps<TItem extends { id?: string }> =
@@ -71,7 +76,7 @@ export const InfiniteScrollWithComponents = forwardRef(
7176
<EndReachedIndicator hasEnded={topEndReached} reached='top' />
7277
<InfiniteScrollPaginator {...componentProps} ref={ref}>
7378
{items.map((item) => (
74-
<ListItem item={item} key={item.id} />
79+
<ListItem item={item} key={paginator.getItemId?.(item) ?? item.id} />
7580
))}
7681
<LoadingNextPageIndicator isLoading={isLoading} />
7782
</InfiniteScrollPaginator>

0 commit comments

Comments
 (0)