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

Commit 0195514

Browse files
committed
Prevent an exception getting scroll node
Don't try to findDOMNode before we're mounted as it makes react angry.
1 parent e38437e commit 0195514

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/views/rooms/RoomList.js

Lines changed: 11 additions & 1 deletion
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,9 +71,12 @@ 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

74-
componentDidUpdate: function() {
78+
componentDidUpdate: function(prevp, nextp) {
79+
console.log(prevp, nextp);
7580
// Reinitialise the stickyHeaders when the component is updated
7681
this._updateStickyHeaders(true);
7782
this._repositionIncomingCallBox(undefined, false);
@@ -106,6 +111,8 @@ module.exports = React.createClass({
106111
},
107112

108113
componentWillUnmount: function() {
114+
this.mounted = false;
115+
109116
dis.unregister(this.dispatcherRef);
110117
if (MatrixClientPeg.get()) {
111118
MatrixClientPeg.get().removeListener("Room", this.onRoom);
@@ -311,6 +318,7 @@ module.exports = React.createClass({
311318
},
312319

313320
_getScrollNode: function() {
321+
if (!this.mounted) return null;
314322
var panel = ReactDOM.findDOMNode(this);
315323
if (!panel) return null;
316324

@@ -337,6 +345,7 @@ module.exports = React.createClass({
337345
var incomingCallBox = document.getElementById("incomingCallBox");
338346
if (incomingCallBox && incomingCallBox.parentElement) {
339347
var scrollArea = this._getScrollNode();
348+
if (!scrollArea) return;
340349
// Use the offset of the top of the scroll area from the window
341350
// as this is used to calculate the CSS fixed top position for the stickies
342351
var scrollAreaOffset = scrollArea.getBoundingClientRect().top + window.pageYOffset;
@@ -360,6 +369,7 @@ module.exports = React.createClass({
360369
// properly through React
361370
_initAndPositionStickyHeaders: function(initialise, scrollToPosition) {
362371
var scrollArea = this._getScrollNode();
372+
if (!scrollArea) return;
363373
// Use the offset of the top of the scroll area from the window
364374
// as this is used to calculate the CSS fixed top position for the stickies
365375
var scrollAreaOffset = scrollArea.getBoundingClientRect().top + window.pageYOffset;

0 commit comments

Comments
 (0)