From 9a4915f0c6a1eaa5ac8774e552e3a6182b06a341 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Thu, 16 Apr 2026 11:46:41 +0530 Subject: [PATCH 1/3] Fix the issue for number count in media modal --- src/js/media/models/attachments.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/js/media/models/attachments.js b/src/js/media/models/attachments.js index 23510bd949f4c..f6185669dce86 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,11 @@ 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). + attachments.on( 'add', this._addToTotalAttachments, this ); + attachments.on( 'remove', this._removeFromTotalAttachments, this ); + // Used for the search results. this.trigger( 'attachments:received', this ); return this; From 953f13fc80c0dedc0ddbd3b131fa09a539462a73 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Mon, 4 May 2026 16:18:18 +0530 Subject: [PATCH 2/3] Add QUnit test case for the attachment model --- src/js/media/models/attachments.js | 1 + tests/qunit/index.html | 1 + .../qunit/wp-includes/js/media/test-models.js | 107 ++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 tests/qunit/wp-includes/js/media/test-models.js diff --git a/src/js/media/models/attachments.js b/src/js/media/models/attachments.js index f6185669dce86..1683494388283 100644 --- a/src/js/media/models/attachments.js +++ b/src/js/media/models/attachments.js @@ -310,6 +310,7 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen // 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 ); 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 @@ +