Fix emitter handler leak in ThreadView (#10803)
* Fix emitter handler leak in ThreadView * Help gc react stateNodes
This commit is contained in:
parent
c7ed23e972
commit
499d8110b3
2 changed files with 8 additions and 11 deletions
|
@ -116,22 +116,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||||
this.setupThread(this.props.mxEvent);
|
this.setupThread(this.props.mxEvent);
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
|
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
|
this.props.room.on(ThreadEvent.New, this.onNewThread);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount(): void {
|
public componentWillUnmount(): void {
|
||||||
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
||||||
const roomId = this.props.mxEvent.getRoomId();
|
const roomId = this.props.mxEvent.getRoomId();
|
||||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
|
||||||
room?.removeListener(ThreadEvent.New, this.onNewThread);
|
|
||||||
SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
||||||
|
|
||||||
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
|
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
|
||||||
|
@ -147,6 +137,10 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||||
action: Action.ViewThread,
|
action: Action.ViewThread,
|
||||||
thread_id: null,
|
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 {
|
public componentDidUpdate(prevProps: IProps): void {
|
||||||
|
|
|
@ -294,6 +294,9 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
|
||||||
this.unmounted = true;
|
this.unmounted = true;
|
||||||
unmountPills(this.pills);
|
unmountPills(this.pills);
|
||||||
unmountTooltips(this.tooltips);
|
unmountTooltips(this.tooltips);
|
||||||
|
|
||||||
|
this.pills = [];
|
||||||
|
this.tooltips = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public shouldComponentUpdate(nextProps: Readonly<IBodyProps>, nextState: Readonly<IState>): boolean {
|
public shouldComponentUpdate(nextProps: Readonly<IBodyProps>, nextState: Readonly<IState>): boolean {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue