From f739008cbd445bee72474efc9a2be79ec0e9d8ef Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 15 Feb 2018 21:20:16 +0000 Subject: [PATCH] Render reference list from originalDomElements until modified This helps on wikis where there are no real refs because they are template-generated, and is a performance improvement elsewhere as re-rendering long ref lists can be slow. Bug: T187495 Change-Id: I47a9206ff7ee61f8fd716dc7658b8bfad927f656 --- modules/ve-cite/ve.ce.MWReferencesListNode.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/ve-cite/ve.ce.MWReferencesListNode.js b/modules/ve-cite/ve.ce.MWReferencesListNode.js index 9b53f0a99..b89747147 100644 --- a/modules/ve-cite/ve.ce.MWReferencesListNode.js +++ b/modules/ve-cite/ve.ce.MWReferencesListNode.js @@ -26,10 +26,12 @@ ve.ce.MWReferencesListNode = function VeCeMWReferencesListNode() { // Properties this.internalList = null; this.listNode = null; + this.modified = false; // DOM changes this.$element.addClass( 've-ce-mwReferencesListNode' ); this.$reflist = $( '
    ' ).addClass( 'mw-references references' ); + this.$originalRefList = null; this.$refmsg = $( '

    ' ) .addClass( 've-ce-mwReferencesListNode-muted' ); @@ -110,6 +112,7 @@ ve.ce.MWReferencesListNode.prototype.onTeardown = function () { ve.ce.MWReferencesListNode.prototype.onInternalListUpdate = function ( groupsChanged ) { // Only update if this group has been changed if ( groupsChanged.indexOf( this.model.getAttribute( 'listGroup' ) ) !== -1 ) { + this.modified = true; this.updateDebounced(); } }; @@ -125,6 +128,7 @@ ve.ce.MWReferencesListNode.prototype.onAttributeChange = function ( key ) { switch ( key ) { case 'listGroup': this.updateDebounced(); + this.modified = true; break; case 'isResponsive': this.updateClasses(); @@ -157,6 +161,17 @@ ve.ce.MWReferencesListNode.prototype.update = function () { listGroup = this.model.getAttribute( 'listGroup' ), nodes = internalList.getNodeGroup( listGroup ); + // Just use Parsoid-provided DOM for first rendering + // NB: Technically this.modified could be reset to false if this + // node is re-attached, but that is an unlikely edge case. + if ( !this.modified && this.model.getElement().originalDomElementsIndex ) { + this.$originalRefList = $( this.model.getStore().value( + this.model.getElement().originalDomElementsIndex + ) ); + this.$element.append( this.$originalRefList ); + return; + } + function updateGeneratedContent( viewNode, $li ) { // HACK: PHP parser doesn't wrap single lines in a paragraph if ( @@ -179,6 +194,10 @@ ve.ce.MWReferencesListNode.prototype.update = function () { viewNode.destroy(); } + if ( this.$originalRefList ) { + this.$originalRefList.remove(); + this.$originalRefList = null; + } this.$reflist.detach().empty(); this.$refmsg.detach();