Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 499d811

Browse files
authored
Fix emitter handler leak in ThreadView (#10803)
* Fix emitter handler leak in ThreadView * Help gc react stateNodes
1 parent c7ed23e commit 499d811

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/components/structures/ThreadView.tsx

+5-11
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
116116
this.setupThread(this.props.mxEvent);
117117
this.dispatcherRef = dis.register(this.onAction);
118118

119-
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
120-
121-
if (!room) {
122-
throw new Error(
123-
`Unable to find room ${this.props.mxEvent.getRoomId()} for thread ${this.props.mxEvent.getId()}`,
124-
);
125-
}
126-
127-
room.on(ThreadEvent.New, this.onNewThread);
119+
this.props.room.on(ThreadEvent.New, this.onNewThread);
128120
}
129121

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

137127
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
@@ -147,6 +137,10 @@ export default class ThreadView extends React.Component<IProps, IState> {
147137
action: Action.ViewThread,
148138
thread_id: null,
149139
});
140+
141+
this.state.thread?.off(ThreadEvent.NewReply, this.updateThreadRelation);
142+
this.props.room.off(RoomEvent.LocalEchoUpdated, this.updateThreadRelation);
143+
this.props.room.removeListener(ThreadEvent.New, this.onNewThread);
150144
}
151145

152146
public componentDidUpdate(prevProps: IProps): void {

src/components/views/messages/TextualBody.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
294294
this.unmounted = true;
295295
unmountPills(this.pills);
296296
unmountTooltips(this.tooltips);
297+
298+
this.pills = [];
299+
this.tooltips = [];
297300
}
298301

299302
public shouldComponentUpdate(nextProps: Readonly<IBodyProps>, nextState: Readonly<IState>): boolean {

0 commit comments

Comments
 (0)