Improve `remove_duplicate_notices` which fixes issue 35005 (#40170)

* Fix issue 35005

* Changelog.

---------

Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com>
This commit is contained in:
Johan van der Molen 2023-10-02 21:52:37 +02:00 committed by GitHub
parent 0885808c07
commit ef36c24858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fixes the logic responsible for removing duplicate notices from the (classic) cart page.

View File

@ -60,23 +60,22 @@ jQuery( function( $ ) {
/**
* Removes duplicate notices.
*
* @param {JQuery Object} notices
* @param {JQuery Object} $notices
*/
var remove_duplicate_notices = function( notices ) {
var seen = [];
var new_notices = notices;
var remove_duplicate_notices = function( $notices ) {
var seen = new Set();
var deduplicated_notices = [];
notices.each( function( index ) {
var text = $( this ).text();
$notices.each( function() {
const text = $( this ).text();
if ( 'undefined' === typeof seen[ text ] ) {
seen[ text ] = true;
} else {
new_notices.splice( index, 1 );
if ( ! seen.has( text ) ) {
seen.add( text );
deduplicated_notices.push( this );
}
} );
return new_notices;
return $( deduplicated_notices );
};
/**