Skip to content

Commit 82f2e47

Browse files
committed
Avoid re-rendering RoomList on room switch
See matrix-org/matrix-react-sdk#1375
1 parent 079f39e commit 82f2e47

2 files changed

Lines changed: 26 additions & 66 deletions

File tree

‎src/components/structures/LeftPanel.js‎

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ var LeftPanel = React.createClass({
3636

3737
getInitialState: function() {
3838
return {
39-
showCallElement: null,
4039
searchFilter: '',
4140
};
4241
},
@@ -45,26 +44,25 @@ var LeftPanel = React.createClass({
4544
this.focusedElement = null;
4645
},
4746

48-
componentDidMount: function() {
49-
this.dispatcherRef = dis.register(this.onAction);
50-
},
51-
52-
componentWillReceiveProps: function(newProps) {
53-
this._recheckCallElement(newProps.selectedRoom);
54-
},
55-
56-
componentWillUnmount: function() {
57-
dis.unregister(this.dispatcherRef);
58-
},
47+
shouldComponentUpdate: function(nextProps, nextState) {
48+
// MatrixChat will update whenever the user switches
49+
// rooms, but propagating this chnage all the way down
50+
// the react tree is quite slow, so we cut this off
51+
// here. The RoomTiles listen for the room change
52+
// events themselves to know when to update.
53+
// We just need to update if any of these things change.
54+
if (
55+
this.props.collapsed !== nextProps.collapsed ||
56+
this.props.opacity !== nextProps.opacity
57+
) {
58+
return true;
59+
}
5960

60-
onAction: function(payload) {
61-
switch (payload.action) {
62-
// listen for call state changes to prod the render method, which
63-
// may hide the global CallView if the call it is tracking is dead
64-
case 'call_state':
65-
this._recheckCallElement(this.props.selectedRoom);
66-
break;
61+
if (this.state.searchFilter !== nextState.searchFilter) {
62+
return true;
6763
}
64+
65+
return false;
6866
},
6967

7068
_onFocus: function(ev) {
@@ -152,74 +150,41 @@ var LeftPanel = React.createClass({
152150
}
153151
},
154152

155-
_recheckCallElement: function(selectedRoomId) {
156-
// if we aren't viewing a room with an ongoing call, but there is an
157-
// active call, show the call element - we need to do this to make
158-
// audio/video not crap out
159-
var activeCall = CallHandler.getAnyActiveCall();
160-
var callForRoom = CallHandler.getCallForRoom(selectedRoomId);
161-
var showCall = (activeCall && activeCall.call_state === 'connected' && !callForRoom);
162-
this.setState({
163-
showCallElement: showCall
164-
});
165-
},
166-
167153
onHideClick: function() {
168154
dis.dispatch({
169155
action: 'hide_left_panel',
170156
});
171157
},
172158

173-
onCallViewClick: function() {
174-
var call = CallHandler.getAnyActiveCall();
175-
if (call) {
176-
dis.dispatch({
177-
action: 'view_room',
178-
room_id: call.groupRoomId || call.roomId,
179-
});
180-
}
181-
},
182-
183159
onSearch: function(term) {
184160
this.setState({ searchFilter: term });
185161
},
186162

187163
render: function() {
188-
var RoomList = sdk.getComponent('rooms.RoomList');
189-
var BottomLeftMenu = sdk.getComponent('structures.BottomLeftMenu');
164+
const RoomList = sdk.getComponent('rooms.RoomList');
165+
const BottomLeftMenu = sdk.getComponent('structures.BottomLeftMenu');
166+
const CallPreview = sdk.getComponent('voip.CallPreview');
190167

191-
var topBox;
168+
let topBox;
192169
if (MatrixClientPeg.get().isGuest()) {
193-
var LoginBox = sdk.getComponent('structures.LoginBox');
170+
const LoginBox = sdk.getComponent('structures.LoginBox');
194171
topBox = <LoginBox collapsed={ this.props.collapsed }/>;
195-
}
196-
else {
197-
var SearchBox = sdk.getComponent('structures.SearchBox');
172+
} else {
173+
const SearchBox = sdk.getComponent('structures.SearchBox');
198174
topBox = <SearchBox collapsed={ this.props.collapsed } onSearch={ this.onSearch } />;
199175
}
200176

201-
var classes = "mx_LeftPanel mx_fadable";
177+
let classes = "mx_LeftPanel mx_fadable";
202178
if (this.props.collapsed) {
203179
classes += " collapsed";
204180
}
205181

206-
var callPreview;
207-
if (this.state.showCallElement && !this.props.collapsed) {
208-
var CallView = sdk.getComponent('voip.CallView');
209-
callPreview = (
210-
<CallView
211-
className="mx_LeftPanel_callView" showVoice={true} onClick={this.onCallViewClick}
212-
ConferenceHandler={VectorConferenceHandler} />
213-
);
214-
}
215-
216182
return (
217183
<aside className={classes} style={{ opacity: this.props.opacity }}
218184
onKeyDown={ this._onKeyDown } onFocus={ this._onFocus } onBlur={ this._onBlur }>
219185
{ topBox }
220-
{ callPreview }
186+
<CallPreview ConferenceHandler={VectorConferenceHandler} />
221187
<RoomList
222-
selectedRoom={this.props.selectedRoom}
223188
collapsed={this.props.collapsed}
224189
searchFilter={this.state.searchFilter}
225190
ConferenceHandler={VectorConferenceHandler} />

‎src/components/structures/RoomSubList.js‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ var RoomSubList = React.createClass({
7575

7676
order: React.PropTypes.string.isRequired,
7777

78-
// undefined if no room is selected (eg we are showing settings)
79-
selectedRoom: React.PropTypes.string,
80-
8178
// passed through to RoomTile and used to highlight room with `!` regardless of notifications count
8279
isInvite: React.PropTypes.bool,
8380

@@ -370,15 +367,13 @@ var RoomSubList = React.createClass({
370367
var self = this;
371368
var DNDRoomTile = sdk.getComponent("rooms.DNDRoomTile");
372369
return this.state.sortedList.map(function(room) {
373-
var selected = room.roomId == self.props.selectedRoom;
374370
// XXX: is it evil to pass in self as a prop to RoomTile?
375371
return (
376372
<DNDRoomTile
377373
room={ room }
378374
roomSubList={ self }
379375
key={ room.roomId }
380376
collapsed={ self.props.collapsed || false}
381-
selected={ selected }
382377
unread={ Unread.doesRoomHaveUnreadMessages(room) }
383378
highlight={ room.getUnreadNotificationCount('highlight') > 0 || self.props.isInvite }
384379
isInvite={ self.props.isInvite }

0 commit comments

Comments
 (0)