Skip to content

Commit f50dcf4

Browse files
adamsilversteinramonjdmcsfyouknowriad
committed
Fix script module dequeue race condition (#76170)
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: mcsf <mcsf@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
1 parent e617676 commit f50dcf4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/wp-build/templates/module-registration.php.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
* Register all script modules.
1111
*/
1212
function {{PREFIX}}_register_script_modules() {
13+
// Ensure this only runs once. wp_default_scripts can fire multiple times,
14+
// and each wp_deregister_script_module() call also dequeues the module.
15+
// If a module was enqueued between calls, repeated deregister/register
16+
// cycles would lose the enqueue state.
17+
static $already_registered = false;
18+
if ( $already_registered ) {
19+
return;
20+
}
21+
$already_registered = true;
22+
1323
// Load build constants
1424
$build_constants = require __DIR__ . '/constants.php';
1525
$modules_dir = __DIR__ . '/modules';

0 commit comments

Comments
 (0)