From 01955146e99bcee254e8bc191a5755bea096b598 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 18 May 2017 17:33:32 +0100 Subject: [PATCH] Prevent an exception getting scroll node Don't try to findDOMNode before we're mounted as it makes react angry. --- src/components/views/rooms/RoomList.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 611dd10780..7a502f0461 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -50,6 +50,8 @@ module.exports = React.createClass({ }, componentWillMount: function() { + this.mounted = false; + var cli = MatrixClientPeg.get(); cli.on("Room", this.onRoom); cli.on("deleteRoom", this.onDeleteRoom); @@ -69,9 +71,12 @@ module.exports = React.createClass({ this.dispatcherRef = dis.register(this.onAction); // Initialise the stickyHeaders when the component is created this._updateStickyHeaders(true); + + this.mounted = true; }, - componentDidUpdate: function() { + componentDidUpdate: function(prevp, nextp) { + console.log(prevp, nextp); // Reinitialise the stickyHeaders when the component is updated this._updateStickyHeaders(true); this._repositionIncomingCallBox(undefined, false); @@ -106,6 +111,8 @@ module.exports = React.createClass({ }, componentWillUnmount: function() { + this.mounted = false; + dis.unregister(this.dispatcherRef); if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("Room", this.onRoom); @@ -311,6 +318,7 @@ module.exports = React.createClass({ }, _getScrollNode: function() { + if (!this.mounted) return null; var panel = ReactDOM.findDOMNode(this); if (!panel) return null; @@ -337,6 +345,7 @@ module.exports = React.createClass({ var incomingCallBox = document.getElementById("incomingCallBox"); if (incomingCallBox && incomingCallBox.parentElement) { var scrollArea = this._getScrollNode(); + if (!scrollArea) return; // Use the offset of the top of the scroll area from the window // as this is used to calculate the CSS fixed top position for the stickies var scrollAreaOffset = scrollArea.getBoundingClientRect().top + window.pageYOffset; @@ -360,6 +369,7 @@ module.exports = React.createClass({ // properly through React _initAndPositionStickyHeaders: function(initialise, scrollToPosition) { var scrollArea = this._getScrollNode(); + if (!scrollArea) return; // Use the offset of the top of the scroll area from the window // as this is used to calculate the CSS fixed top position for the stickies var scrollAreaOffset = scrollArea.getBoundingClientRect().top + window.pageYOffset;