diff --git a/src/js/media/models/attachments.js b/src/js/media/models/attachments.js index 23510bd949f4c..1683494388283 100644 --- a/src/js/media/models/attachments.js +++ b/src/js/media/models/attachments.js @@ -212,8 +212,6 @@ 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 ); this.validateAll( attachments ); return this; @@ -310,6 +308,12 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen this.reset( [], { silent: true } ); this.observe( attachments ); + // Bind total attachment count tracking only to the mirrored query + // collection, not to additional observed collections (e.g. selection). + // See Trac #65053. + attachments.on( 'add', this._addToTotalAttachments, this ); + attachments.on( 'remove', this._removeFromTotalAttachments, this ); + // Used for the search results. this.trigger( 'attachments:received', this ); return this; diff --git a/tests/qunit/index.html b/tests/qunit/index.html index 9fd35f0c1ffc2..a6b6177014586 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -166,6 +166,7 @@ +