From 9a4915f0c6a1eaa5ac8774e552e3a6182b06a341 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Thu, 16 Apr 2026 11:46:41 +0530 Subject: [PATCH] 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;