You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### π― Goal
This PR covers a range of issues that originate from incorrect
initialization of message list state. All the cases are covered below.
### π Implementation details
#### `ChannelList`, `Channel`, `MessageList`, `VirtualizedMessageList`
not respecting the message limits
We have several default limits listed in the `limit.ts` file. However
they were not always respected:
1. `MessageList`, `VirtualizedMessageList` didn't use
`DEFAULT_NEXT_CHANNEL_PAGE_SIZE` and defaulted to the hard-coded message
limit of 100.
2. `Channel` didn't use `DEFAULT_INITIAL_CHANNEL_PAGE_SIZE` when
fetching the first page of messages.
3. `ChannelList` didn't use `DEFAULT_INITIAL_CHANNEL_PAGE_SIZE` as the
message limit per channel when fetching channels.
This is now fixed.
#### False-negative `hasMore` when messages are fetched by `ChannelList`
We have two main ways to initialize the message list: it can be
initialized by the `Channel` component; or it can be initialized by the
`ChannelList` component (using `usePaginatedChannels` hook). If the
message list is initialized by the `ChannelList`, the `Channel`
component will not try to query the channel, and will use messages
fetched by the `ChannelList` instead.
The problem here is that to determine if the channel has more messages
to load, we used to compare the number of messages currently in the
channel with the limit set on the `Channel`. But since it was not the
`Channel` but the `ChannelList` that fetched the messages, this check
makes no sense: `ChannelList` has its own separate limits.
Consider this example:
```tsx
const App = () => (
<Chat client={chatClient}>
<ChannelList options={{ message_limit: 5 }} />
<Channel channelQueryOptions={{ members: { limit: 10 } }}>
{/* ... */}
</Channel>
</Chat>
);
```
The `Channel` component will compare the number of messages fetched by
the `ChannelList` (5) with its own limit (10) and determine that the
channel has no more messages.
This is fixed by always setting `hasMore` to false in channel if it was
not the `Channel` component that fetched the messages. In the worst case
we'll just make one redundant query.
#### The "tall window" problem
In case the message container is very tall, or the message limit for the
initial load is very small, we can run into a situation when the first
page of messages is not long enough to trigger overflow in the message
list. Without overflow, scroll events don't fire, so the next page of
messages is never fetched.
This is not usually a problem in the `VirtualizedMessageList`, since it
will immediately load the next page _once_ in this case. However, the
`MessageList` didn't have this logic in place. It is now added (by
invoking the `scrollListener` _once_ on mount).
**Note:** both `VirtualizedMessageList` and `MessageList` will only try
loading the next page _once_ if the first page of messages is not long
enough to cause overflow. A better solution would be to keep loading
pages until there's overflow or there is no more pages. This solution is
not currently possible to implement in `VirtualizedMessageList`, so for
the sake of consistency I didn't implement it `MessageList` (event
though it is possible).
In most cases this not an issue, since our default page size is 100
messages which is enough to fill even very tall containers.
Copy file name to clipboardexpand all lines: docusaurus/docs/React/components/core-components/message-list.mdx
+4
Original file line number
Diff line number
Diff line change
@@ -476,6 +476,10 @@ Array of allowed message actions (ex: 'edit', 'delete', 'reply'). To disable all
476
476
477
477
The limit to use when paginating new messages (the page size).
478
478
479
+
:::caution
480
+
After mounting, the `MessageList` component checks if the list is completely filled with messages. If there is some space left in the list, `MessageList` will load the next page of messages, but it will do so _only once_. This means that if your `messageLimit` is too low, or if your viewport is very large, the list will not be completely filled. Set the limit with this in mind.
Copy file name to clipboardexpand all lines: docusaurus/docs/React/components/core-components/virtualized-list.mdx
+4
Original file line number
Diff line number
Diff line change
@@ -186,6 +186,10 @@ Custom UI component to display an individual message.
186
186
187
187
The limit to use when paginating messages (the page size).
188
188
189
+
:::caution
190
+
After mounting, the `VirtualizedMessageList` component checks if the list is completely filled with messages. If there is some space left in the list, `VirtualizedMessageList` will load the next page of messages, but it will do so _only once_. This means that if your `messageLimit` is too low, or if your viewport is very large, the list will not be completely filled. Set the limit with this in mind.
0 commit comments