optimize timeline scroll performance

This commit is contained in:
Jamie Kyle 2023-07-31 11:46:16 -07:00 committed by GitHub
parent 1143c0e9ba
commit e5635726ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -399,12 +399,14 @@ export class Timeline extends React.Component<
const newestBottomVisibleMessageId =
getMessageIdFromElement(newestBottomVisible);
this.setState({
this.updatePartiallyVisibleMessageIds(
oldestPartiallyVisibleMessageId,
newestBottomVisibleMessageId,
});
newestBottomVisibleMessageId
);
setIsNearBottom(id, newIsNearBottom);
if (this.props.isNearBottom !== newIsNearBottom) {
setIsNearBottom(id, newIsNearBottom);
}
if (newestBottomVisibleMessageId) {
this.markNewestBottomVisibleMessageRead();
@ -461,6 +463,19 @@ export class Timeline extends React.Component<
this.intersectionObserver.observe(atBottomDetectorEl);
}
private updatePartiallyVisibleMessageIds = throttle(
(
oldestPartiallyVisibleMessageId: string | undefined,
newestBottomVisibleMessageId: string | undefined
) => {
this.setState({
oldestPartiallyVisibleMessageId,
newestBottomVisibleMessageId,
});
},
100
);
private markNewestBottomVisibleMessageRead = throttle((): void => {
const { id, markMessageRead } = this.props;
const { newestBottomVisibleMessageId } = this.state;