Fix emitter handler leak in ThreadView (#10803)

* Fix emitter handler leak in ThreadView

* Help gc react stateNodes
This commit is contained in:
Michael Telatynski 2023-05-05 16:05:58 +01:00 committed by GitHub
parent c7ed23e972
commit 499d8110b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View file

@ -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;
@ -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 {