From c3b3236feeeaa7deacf4f9eebd77d3e1dc81f3a5 Mon Sep 17 00:00:00 2001 From: b1ink0 Date: Tue, 19 Nov 2024 12:49:43 +0530 Subject: [PATCH 1/3] Update JavaScript plugin activation to use queue based approach --- .../includes/admin/plugin-activate-ajax.js | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/plugins/performance-lab/includes/admin/plugin-activate-ajax.js b/plugins/performance-lab/includes/admin/plugin-activate-ajax.js index fd48fbb25..5567a0558 100644 --- a/plugins/performance-lab/includes/admin/plugin-activate-ajax.js +++ b/plugins/performance-lab/includes/admin/plugin-activate-ajax.js @@ -7,22 +7,21 @@ const { i18n, a11y, apiFetch } = wp; const { __ } = i18n; + // Queue to hold pending activation requests. + const activationQueue = []; + let isProcessingActivation = false; + /** - * Handles click events on elements with the class 'perflab-install-active-plugin'. - * - * This asynchronous function listens for click events on the document and executes - * the provided callback function if triggered. + * Enqueues plugin activation requests and starts processing if not already in progress. * - * @param {MouseEvent} event - The click event object that is triggered when the user clicks on the document. - * - * @return {Promise} The asynchronous function returns a promise that resolves to void. + * @param {MouseEvent} event - The click event object. */ - async function handlePluginActivationClick( event ) { - const target = /** @type {HTMLElement} */ ( event.target ); - + function enqueuePluginActivation( event ) { // Prevent the default link behavior. event.preventDefault(); + const target = /** @type {HTMLElement} */ ( event.target ); + if ( target.classList.contains( 'updating-message' ) || target.classList.contains( 'disabled' ) @@ -30,13 +29,38 @@ return; } + target.textContent = __( 'Waiting…', 'performance-lab' ); + + const pluginSlug = target.dataset.pluginSlug; + + activationQueue.push( { target, pluginSlug } ); + + // Start processing the queue if not already doing so. + if ( ! isProcessingActivation ) { + handlePluginActivation(); + } + } + + /** + * Handles activation of feature/plugin using queue based approach. + * + * @return {Promise} The asynchronous function returns a promise that resolves to void. + */ + async function handlePluginActivation() { + if ( 0 === activationQueue.length ) { + isProcessingActivation = false; + return; + } + + isProcessingActivation = true; + + const { target, pluginSlug } = activationQueue.shift(); + target.classList.add( 'updating-message' ); target.textContent = __( 'Activating…', 'performance-lab' ); a11y.speak( __( 'Activating…', 'performance-lab' ) ); - const pluginSlug = target.dataset.pluginSlug; - try { // Activate the plugin/feature via the REST API. await apiFetch( { @@ -76,6 +100,8 @@ target.classList.remove( 'updating-message' ); target.textContent = __( 'Activate', 'performance-lab' ); + } finally { + handlePluginActivation(); } } @@ -83,6 +109,6 @@ document .querySelectorAll( '.perflab-install-active-plugin' ) .forEach( ( item ) => { - item.addEventListener( 'click', handlePluginActivationClick ); + item.addEventListener( 'click', enqueuePluginActivation ); } ); } )(); From 9e98fca67fb38861dee893bd6f57c994713c1027 Mon Sep 17 00:00:00 2001 From: b1ink0 Date: Tue, 19 Nov 2024 14:04:11 +0530 Subject: [PATCH 2/3] Add updating-message class to waiting plugins button --- plugins/performance-lab/includes/admin/plugin-activate-ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/performance-lab/includes/admin/plugin-activate-ajax.js b/plugins/performance-lab/includes/admin/plugin-activate-ajax.js index 5567a0558..7be529792 100644 --- a/plugins/performance-lab/includes/admin/plugin-activate-ajax.js +++ b/plugins/performance-lab/includes/admin/plugin-activate-ajax.js @@ -29,6 +29,7 @@ return; } + target.classList.add( 'updating-message' ); target.textContent = __( 'Waiting…', 'performance-lab' ); const pluginSlug = target.dataset.pluginSlug; @@ -56,7 +57,6 @@ const { target, pluginSlug } = activationQueue.shift(); - target.classList.add( 'updating-message' ); target.textContent = __( 'Activating…', 'performance-lab' ); a11y.speak( __( 'Activating…', 'performance-lab' ) ); From 2f7f863f5735631b18742f4293105ced4eb9fcb1 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 19 Nov 2024 16:31:54 -0800 Subject: [PATCH 3/3] Prepare 3.6.1 release. --- plugins/performance-lab/load.php | 4 ++-- plugins/performance-lab/readme.txt | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/performance-lab/load.php b/plugins/performance-lab/load.php index ffb36724c..6e6698178 100644 --- a/plugins/performance-lab/load.php +++ b/plugins/performance-lab/load.php @@ -5,7 +5,7 @@ * Description: Performance plugin from the WordPress Performance Team, which is a collection of standalone performance features. * Requires at least: 6.5 * Requires PHP: 7.2 - * Version: 3.6.0 + * Version: 3.6.1 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -19,7 +19,7 @@ exit; // Exit if accessed directly. } -define( 'PERFLAB_VERSION', '3.6.0' ); +define( 'PERFLAB_VERSION', '3.6.1' ); define( 'PERFLAB_MAIN_FILE', __FILE__ ); define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) ); define( 'PERFLAB_SCREEN', 'performance-lab' ); diff --git a/plugins/performance-lab/readme.txt b/plugins/performance-lab/readme.txt index ef171cfe1..8cac6e2c0 100644 --- a/plugins/performance-lab/readme.txt +++ b/plugins/performance-lab/readme.txt @@ -2,7 +2,7 @@ Contributors: wordpressdotorg Tested up to: 6.7 -Stable tag: 3.6.0 +Stable tag: 3.6.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, site health, measurement, optimization, diagnostics @@ -71,6 +71,12 @@ Contributions are always welcome! Learn more about how to get involved in the [C == Changelog == += 3.6.1 = + +**Bug Fixes** + +* Fix race condition bug where activating multiple features sequentially could fail to activate some features. ([#1675](https://github.com/WordPress/performance/pull/1675)) + = 3.6.0 = **Enhancements**