From 1e095e105aa828c31db5191aa95252d631460454 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 24 Feb 2016 12:53:39 +0000 Subject: [PATCH] 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. --- src/components/structures/TimelinePanel.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index a1fb1e065c..c8e5482d15 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -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;