Don't update state when no change to read marker

It turns out to be quite expensive to update the state, because we can't do
shouldComponentUpdate on any of the sub-components (because RRs and local echo
sneak in through the back door), and we don't want to trigger a whole render
cycle every time someone presses a key.
This commit is contained in:
Richard van der Hoff 2016-02-24 12:53:39 +00:00
parent 9db58de119
commit 1e095e105a

View file

@ -321,9 +321,11 @@ var TimelinePanel = React.createClass({
// the read-marker should become invisible, so that if the user scrolls
// down, they don't see it.
this.setState({
readMarkerVisible: false,
});
if(this.state.readMarkerVisible) {
this.setState({
readMarkerVisible: false,
});
}
},
/* jump down to the bottom of this room, where new events are arriving
@ -556,6 +558,12 @@ var TimelinePanel = React.createClass({
},
_setReadMarker: function(eventId, eventTs) {
if (TimelinePanel.roomReadMarkerMap[this.props.room.roomId] == eventId) {
// don't update the state (and cause a re-render) if there is
// no change to the RM.
return;
}
// ideally we'd sync these via the server, but for now just stash them
// in a map.
TimelinePanel.roomReadMarkerMap[this.props.room.roomId] = eventId;