diff --git a/src/js/media/models/attachments.js b/src/js/media/models/attachments.js index 23510bd949f4c..68680f530ad61 100644 --- a/src/js/media/models/attachments.js +++ b/src/js/media/models/attachments.js @@ -204,7 +204,7 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen * Start observing another attachments collection change events * and replicate them on this collection. * - * @param {wp.media.model.Attachments} The attachments collection to observe. + * @param {wp.media.model.Attachments} attachments The attachments collection to observe. * @return {wp.media.model.Attachments} Returns itself to allow chaining. */ observe: function( attachments ) { @@ -212,9 +212,19 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen this.observers.push( attachments ); attachments.on( 'add change remove', this._validateHandler, this ); - attachments.on( 'add', this._addToTotalAttachments, this ); - attachments.on( 'remove', this._removeFromTotalAttachments, this ); attachments.on( 'reset', this._validateAllHandler, this ); + + /* + * Only track the total number of attachments for the mirrored query + * collection. Other observed collections, such as the selection, must + * not change the count, otherwise an uploaded attachment that is also + * added to the selection is counted more than once. See ticket #65513. + */ + if ( attachments === this.mirroring ) { + attachments.on( 'add', this._addToTotalAttachments, this ); + attachments.on( 'remove', this._removeFromTotalAttachments, this ); + } + this.validateAll( attachments ); return this; }, @@ -239,7 +249,7 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen return this; }, /** - * Update total attachment count when items are added to a collection. + * Update total attachment count when items are removed from a collection. * * @access private *