From 45e59032265587c79161e59333419ef34a6818b1 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 27 Sep 2020 21:48:36 +0100 Subject: [PATCH] fix uninitialised state and eventlistener leak --- .../views/rooms/RoomUpgradeWarningBar.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomUpgradeWarningBar.js b/src/components/views/rooms/RoomUpgradeWarningBar.js index 531428198e..877cfb39d7 100644 --- a/src/components/views/rooms/RoomUpgradeWarningBar.js +++ b/src/components/views/rooms/RoomUpgradeWarningBar.js @@ -1,5 +1,5 @@ /* -Copyright 2018 New Vector Ltd +Copyright 2018-2020 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -28,6 +28,11 @@ export default class RoomUpgradeWarningBar extends React.Component { recommendation: PropTypes.object.isRequired, }; + constructor(props) { + super(props); + this.state = {}; + } + componentDidMount() { const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", ""); this.setState({upgraded: tombstone && tombstone.getContent().replacement_room}); @@ -35,6 +40,13 @@ export default class RoomUpgradeWarningBar extends React.Component { MatrixClientPeg.get().on("RoomState.events", this._onStateEvents); } + componentWillUnmount() { + const cli = MatrixClientPeg.get(); + if (cli) { + cli.removeListener("RoomState.events", this._onStateEvents); + } + } + _onStateEvents = (event, state) => { if (!this.props.room || event.getRoomId() !== this.props.room.roomId) { return;