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

Fix emitter handler leak in ThreadView #10803

Merged
merged 2 commits into from
May 5, 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
16 changes: 5 additions & 11 deletions src/components/structures/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
this.setupThread(this.props.mxEvent);
this.dispatcherRef = dis.register(this.onAction);

const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());

if (!room) {
throw new Error(
`Unable to find room ${this.props.mxEvent.getRoomId()} for thread ${this.props.mxEvent.getId()}`,
);
}

room.on(ThreadEvent.New, this.onNewThread);
this.props.room.on(ThreadEvent.New, this.onNewThread);
}

public componentWillUnmount(): void {
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
const roomId = this.props.mxEvent.getRoomId();
const room = MatrixClientPeg.get().getRoom(roomId);
room?.removeListener(ThreadEvent.New, this.onNewThread);
SettingsStore.unwatchSetting(this.layoutWatcherRef);

const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
Expand All @@ -147,6 +137,10 @@ export default class ThreadView extends React.Component<IProps, IState> {
action: Action.ViewThread,
thread_id: null,
});

this.state.thread?.off(ThreadEvent.NewReply, this.updateThreadRelation);
this.props.room.off(RoomEvent.LocalEchoUpdated, this.updateThreadRelation);
this.props.room.removeListener(ThreadEvent.New, this.onNewThread);
}

public componentDidUpdate(prevProps: IProps): void {
Expand Down
3 changes: 3 additions & 0 deletions src/components/views/messages/TextualBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
this.unmounted = true;
unmountPills(this.pills);
unmountTooltips(this.tooltips);

this.pills = [];
this.tooltips = [];
}

public shouldComponentUpdate(nextProps: Readonly<IBodyProps>, nextState: Readonly<IState>): boolean {
Expand Down
Loading