From baf2af1afaf5b8618ba55bf5c72a6d2dc659e800 Mon Sep 17 00:00:00 2001 From: Thomas Parslow Date: Tue, 14 Apr 2015 17:31:58 +0100 Subject: [PATCH] Avoid running the HTML sanitizer more often than needed --- index.ios.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/index.ios.js b/index.ios.js index f346bad..90d4c30 100644 --- a/index.ios.js +++ b/index.ios.js @@ -30,6 +30,10 @@ var HTMLWebView = React.createClass({ autoHeight: PropTypes.bool }, + shouldComponentUpdate: function (nextProps, nextState) { + return !_.isEqual(nextProps, this.props) || !_.isEqual(nextState, this.state); + }, + getInitialState: function() { return { contentHeight: 1 @@ -37,10 +41,18 @@ var HTMLWebView = React.createClass({ }, render: function () { + // Don't do the expensive safeHtml operation more often than + // needed. This is assume you don't mutate and reuse the same + // makeSafe config object, please don't do that. + if (this._currentHtml !== this.props.html || !_.isEqual(this._currentMakeSafe, this.props.makeSafe)) { + this._currentHtml = this.props.html; + this._currentMakeSafe = this.props.makeSafe; + this._safeHtml = this.safeHtml(this._currentHtml); + } return ( <_HTMLWebView style={[{height: this.state.contentHeight}, this.props.style]} - html={this.safeHtml(this.props.html)} + html={this._safeHtml} enableScroll={!this.props.autoHeight} onLink={this.onLink} onContentHeight={this.onContentHeight}