Fix emitter handler leak in ThreadView (#10803)

* Fix emitter handler leak in ThreadView

* Help gc react stateNodes
pull/28217/head
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 {

View File

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