Fix script module dequeue race condition#76170
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| if ( $already_registered ) { | ||
| return; | ||
| } | ||
| $already_registered = true; |
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for spotting this! I also went through the test steps in #75909, to make sure that still works.
See: #76182 (comment)
cc @dlind1 for visibility
Is this correct? Or is the repeated firing a result of the fact that class WP_Scripts extends WP_Dependencies {
public function __construct() {
$this->init();
add_action( 'init', array( $this, 'init' ), 0 );
}
public function init() {
do_action_ref_array( 'wp_default_scripts', array( &$this ) );
} |
|
Can we rebase and land this PR. Would be good to get a gutenberg patch release out with this fix. It seems the PR can also impact Core no? cc @ellatrix |
wp_default_scripts fires multiple times per request. Each invocation was calling wp_deregister_script_module() which also dequeues the module, silently destroying enqueue state set between invocations (e.g. @wordpress/vips/loader enqueued on enqueue_block_editor_assets). Add a static guard so the deregister/register cycle only runs once.
d385e56 to
983f504
Compare
|
I rebased this PR and smoked tested again. Is there anything blocking it? |
|
Flaky tests detected in 983f504. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23216283995
|
Co-authored-by: adamsilverstein <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: mcsf <[email protected]> Co-authored-by: youknowriad <[email protected]>
|
Cherry-picked into Gutenberg 22.7 release branch. |

Summary
gutenberg_register_script_modules()is hooked onwp_default_scripts, which fires multiple times per request (once perWP_Scriptsinstantiation)wp_deregister_script_module()→wp_register_script_module()for every modulederegister()also callsdequeue(), any module enqueued between invocations (e.g.@wordpress/vips/loaderenqueued onenqueue_block_editor_assets) has its enqueue silently destroyedstatic $already_registeredguard so the deregister/register cycle only runs oncenpm run buildregeneratesbuild/modules.phpwith the fixTest plan
@wordpress/vips/loaderand@wordpress/vips/workerFailed to resolve module specifier '@wordpress/vips/worker'npm run buildregeneratesbuild/modules.phpwith the static guard🤖 Generated with Claude Code