Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UI performance of long chat channel lists #10631

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions resources/css/bem/chat-conversation-list.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@
align-self: center;
}
}

&__layer {
.own-layer();

@media @mobile {
display: flex;
flex-direction: row;
}
}
}
8 changes: 4 additions & 4 deletions resources/css/utilities.less
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
}
}

.u-full-size {
.full-size();
}

.u-hidden {
display: none !important;
}
Expand All @@ -85,10 +89,6 @@
z-index: @z-index--nav-float !important;
}

.u-full-size {
.full-size();
}

.u-relative {
position: relative;
}
Expand Down
12 changes: 11 additions & 1 deletion resources/js/chat/conversation-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

import { SupportedChannelType, supportedChannelTypes } from 'interfaces/chat/channel-json';
import { chunk } from 'lodash';
import { observer } from 'mobx-react';
import core from 'osu-core-singleton';
import * as React from 'react';
Expand All @@ -21,14 +22,23 @@ function renderChannels(type: SupportedChannelType) {
if (channels.length > 0 || type === 'ANNOUNCE' && core.dataStore.chatState.canChatAnnounce) {
const title = trans(`chat.channels.list.title.${type}`);

// Optimization so that the channel list can be rendered as several smaller layers.
// This shouldn't be too large, otherwise, Safari can't handle the layer; it also can't be
// too small, otherwise there'll be too many layout recalculations.
const chunks = chunk(channels, 100);

return (
<React.Fragment key={type}>
<div className='chat-conversation-list__group'>
<div className='chat-conversation-list__header'>
<span className='chat-conversation-list__header-text'>{title}</span>
<span className='chat-conversation-list__header-icon' title={title}><i className={icons[type]} /></span>
</div>
{channels.map((channel) => <ConversationListItem key={channel.channelId} channel={channel} />)}
{chunks.map((c, index) => (
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a comment somewhere in here mentioning that this is an optimisation.

<div key={index} className='chat-conversation-list__layer'>
{c.map((channel) => <ConversationListItem key={channel.channelId} channel={channel} />)}
</div>
))}
{type === 'ANNOUNCE' && <CreateAnnouncementButton />}
</div>
<div className='chat-conversation-list-separator' />
Expand Down