Make WordPress Core

Ticket #40966: 40966.7.diff

File 40966.7.diff, 3.5 KB (added by simonemanfre, 21 months ago)

Add class 'is-enqueued' to prevent elements being added twice to the update queue

  • src/js/_enqueues/wp/updates.js

    diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js
    index 55eb0fbf95..269ac3c54f 100644
    a b  
    516516                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    517517                        $pluginRow     = $( 'tr[data-plugin="' + response.plugin + '"]' )
    518518                                .removeClass( 'update' )
     519                                .removeClass( 'is-enqueued' )
    519520                                .addClass( 'updated' );
    520521                        $updateMessage = $pluginRow.find( '.update-message' )
    521522                                .removeClass( 'updating-message notice-warning' )
     
    585586                );
    586587
    587588                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
     589                        $pluginRow     = $( 'tr[data-plugin="' + response.plugin + '"]' ).removeClass( 'is-enqueued' );
     590
    588591                        if ( response.plugin ) {
    589592                                $message = $( 'tr[data-plugin="' + response.plugin + '"]' ).find( '.update-message' );
    590593                        } else {
     
    16161619
    16171620                // DecrementCount from update count.
    16181621                if ( 'themes' === pagenow ) {
    1619                     var theme = _.find( _wpThemeSettings.themes, { id: response.slug } );
    1620                     if ( theme.hasUpdate ) {
    1621                         wp.updates.decrementCount( 'theme' );
    1622                     }
     1622                        var theme = _.find( _wpThemeSettings.themes, { id: response.slug } );
     1623                        if ( theme.hasUpdate ) {
     1624                                wp.updates.decrementCount( 'theme' );
     1625                        }
    16231626                }
    16241627
    16251628                wp.a11y.speak( _x( 'Deleted!', 'theme' ) );
     
    24682471                                        return;
    24692472                                }
    24702473
     2474                                // Don't add items to the update queue again even if the user click the update button several times.
     2475                                if ( 'update-selected' === bulkAction && $itemRow.hasClass( 'is-enqueued' )) {
     2476                                        return;
     2477                                }
     2478
     2479                                $itemRow.addClass( 'is-enqueued' );
     2480
    24712481                                // Add it to the queue.
    24722482                                wp.updates.queue.push( {
    24732483                                        action: action,