Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 3.6.1 release changes back into trunk #1684

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions plugins/performance-lab/includes/admin/plugin-activate-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>} 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' )
Expand All @@ -31,12 +30,37 @@
}

target.classList.add( 'updating-message' );
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<void>} 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.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( {
Expand Down Expand Up @@ -76,13 +100,15 @@

target.classList.remove( 'updating-message' );
target.textContent = __( 'Activate', 'performance-lab' );
} finally {
handlePluginActivation();
}
}

// Attach the event listeners.
document
.querySelectorAll( '.perflab-install-active-plugin' )
.forEach( ( item ) => {
item.addEventListener( 'click', handlePluginActivationClick );
item.addEventListener( 'click', enqueuePluginActivation );
} );
} )();
4 changes: 2 additions & 2 deletions plugins/performance-lab/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' );
Expand Down
8 changes: 7 additions & 1 deletion plugins/performance-lab/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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**
Expand Down
Loading