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

Commit 726cd60

Browse files
authored
Merge pull request #902 from matrix-org/dbkr/prevent_illegal_finddomnode
Prevent an exception getting scroll node
2 parents 46242a1 + 8fe3fa9 commit 726cd60

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/components/views/rooms/RoomList.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ module.exports = React.createClass({
5050
},
5151

5252
componentWillMount: function() {
53+
this.mounted = false;
54+
5355
var cli = MatrixClientPeg.get();
5456
cli.on("Room", this.onRoom);
5557
cli.on("deleteRoom", this.onDeleteRoom);
@@ -69,6 +71,8 @@ module.exports = React.createClass({
6971
this.dispatcherRef = dis.register(this.onAction);
7072
// Initialise the stickyHeaders when the component is created
7173
this._updateStickyHeaders(true);
74+
75+
this.mounted = true;
7276
},
7377

7478
componentDidUpdate: function() {
@@ -106,6 +110,8 @@ module.exports = React.createClass({
106110
},
107111

108112
componentWillUnmount: function() {
113+
this.mounted = false;
114+
109115
dis.unregister(this.dispatcherRef);
110116
if (MatrixClientPeg.get()) {
111117
MatrixClientPeg.get().removeListener("Room", this.onRoom);
@@ -311,6 +317,7 @@ module.exports = React.createClass({
311317
},
312318

313319
_getScrollNode: function() {
320+
if (!this.mounted) return null;
314321
var panel = ReactDOM.findDOMNode(this);
315322
if (!panel) return null;
316323

@@ -337,6 +344,7 @@ module.exports = React.createClass({
337344
var incomingCallBox = document.getElementById("incomingCallBox");
338345
if (incomingCallBox && incomingCallBox.parentElement) {
339346
var scrollArea = this._getScrollNode();
347+
if (!scrollArea) return;
340348
// Use the offset of the top of the scroll area from the window
341349
// as this is used to calculate the CSS fixed top position for the stickies
342350
var scrollAreaOffset = scrollArea.getBoundingClientRect().top + window.pageYOffset;
@@ -360,6 +368,7 @@ module.exports = React.createClass({
360368
// properly through React
361369
_initAndPositionStickyHeaders: function(initialise, scrollToPosition) {
362370
var scrollArea = this._getScrollNode();
371+
if (!scrollArea) return;
363372
// Use the offset of the top of the scroll area from the window
364373
// as this is used to calculate the CSS fixed top position for the stickies
365374
var scrollAreaOffset = scrollArea.getBoundingClientRect().top + window.pageYOffset;

0 commit comments

Comments
 (0)