@@ -18,6 +18,7 @@ limitations under the License.
1818
1919var React = require ( 'react' ) ;
2020var ReactDOM = require ( 'react-dom' ) ;
21+ var highlight = require ( 'highlight.js' ) ;
2122var HtmlUtils = require ( '../../../HtmlUtils' ) ;
2223var linkify = require ( 'linkifyjs' ) ;
2324var linkifyElement = require ( 'linkifyjs/element' ) ;
@@ -62,17 +63,34 @@ module.exports = React.createClass({
6263 } ,
6364
6465 componentDidMount : function ( ) {
66+ this . _unmounted = false ;
67+
6568 linkifyElement ( this . refs . content , linkifyMatrix . options ) ;
6669 this . calculateUrlPreview ( ) ;
6770
68- if ( this . props . mxEvent . getContent ( ) . format === "org.matrix.custom.html" )
69- HtmlUtils . highlightDom ( ReactDOM . findDOMNode ( this ) ) ;
71+ if ( this . props . mxEvent . getContent ( ) . format === "org.matrix.custom.html" ) {
72+ const blocks = ReactDOM . findDOMNode ( this ) . getElementsByTagName ( "code" ) ;
73+ if ( blocks . length > 0 ) {
74+ // Do this asynchronously: parsing code takes time and we don't
75+ // need to block the DOM update on it.
76+ setTimeout ( ( ) => {
77+ if ( this . _unmounted ) return ;
78+ for ( let i = 0 ; i < blocks . length ; i ++ ) {
79+ highlight . highlightBlock ( blocks [ i ] ) ;
80+ }
81+ } , 10 ) ;
82+ }
83+ }
7084 } ,
7185
7286 componentDidUpdate : function ( ) {
7387 this . calculateUrlPreview ( ) ;
7488 } ,
7589
90+ componentWillUnmount : function ( ) {
91+ this . _unmounted = true ;
92+ } ,
93+
7694 shouldComponentUpdate : function ( nextProps , nextState ) {
7795 //console.log("shouldComponentUpdate: ShowUrlPreview for %s is %s", this.props.mxEvent.getId(), this.props.showUrlPreview);
7896
0 commit comments