Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Throttle recheckFirstVisibleEventIndex()
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner committed May 11, 2022
1 parent 33092f1 commit cebd65b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
import { SyncState } from 'matrix-js-sdk/src/sync';
import { RoomMember, RoomMemberEvent } from 'matrix-js-sdk/src/models/room-member';
import { debounce } from 'lodash';
import { debounce, throttle } from 'lodash';
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { Thread } from 'matrix-js-sdk/src/models/thread';
Expand Down Expand Up @@ -810,10 +810,13 @@ class TimelinePanel extends React.Component<IProps, IState> {

if (!this.state.events.includes(ev)) return;

const firstVisibleEventIndex = this.checkForPreJoinUISI(this.state.events);
if (firstVisibleEventIndex !== this.state.firstVisibleEventIndex) {
this.setState({ firstVisibleEventIndex });
}
const recheckFirstVisibleEventIndex = throttle(() => {

This comment has been minimized.

Copy link
@t3chguy

t3chguy May 11, 2022

Member

This won't throttle anything, given you're creating the throttle'd method on every call

This comment has been minimized.

Copy link
@SimonBrandner

SimonBrandner May 11, 2022

Author Contributor

🤦

const firstVisibleEventIndex = this.checkForPreJoinUISI(this.state.events);
if (firstVisibleEventIndex !== this.state.firstVisibleEventIndex) {
this.setState({ firstVisibleEventIndex });
}
}, 500, { leading: true, trailing: true });
recheckFirstVisibleEventIndex();

// Need to update as we don't display event tiles for events that
// haven't yet been decrypted. The event will have just been updated
Expand Down

0 comments on commit cebd65b

Please sign in to comment.