From 499d8110b3cce889cc0836431819a7f8fadb8847 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 5 May 2023 16:05:58 +0100 Subject: [PATCH] Fix emitter handler leak in ThreadView (#10803) * Fix emitter handler leak in ThreadView * Help gc react stateNodes --- src/components/structures/ThreadView.tsx | 16 +++++----------- src/components/views/messages/TextualBody.tsx | 3 +++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index a59e93dda1..b0c35ef65f 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -116,22 +116,12 @@ export default class ThreadView extends React.Component { 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; @@ -147,6 +137,10 @@ export default class ThreadView extends React.Component { 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 { diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx index 488c699aed..fa4008e144 100644 --- a/src/components/views/messages/TextualBody.tsx +++ b/src/components/views/messages/TextualBody.tsx @@ -294,6 +294,9 @@ export default class TextualBody extends React.Component { this.unmounted = true; unmountPills(this.pills); unmountTooltips(this.tooltips); + + this.pills = []; + this.tooltips = []; } public shouldComponentUpdate(nextProps: Readonly, nextState: Readonly): boolean {