Skip to content

Commit

Permalink
Avoid running the HTML sanitizer more often than needed
Browse files Browse the repository at this point in the history
  • Loading branch information
almost committed Apr 14, 2015
1 parent 7975749 commit baf2af1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,29 @@ 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
};
},

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}
Expand Down

0 comments on commit baf2af1

Please sign in to comment.