Make WordPress Core

Opened 16 months ago

Last modified 15 months ago

#59114 new defect (bug)

Infinite loop after upgrading from WordPress 6.1.3 to 6.2

Reported by: kevincorrigan's profile kevincorrigan Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.3
Component: Script Loader Keywords:
Focuses: Cc:

Description

Regeristing a function with the 'wp_video_shortcode_library' filter hook that enqueues a script causes an infinite loop, resulting in WordPress running out of memory.

It seems that the $wp_scripts global is being set to null at some point and being reinitialized, which causes this loop since the 'wp_video_shortcode_library' filter is called as part of the wp_default_scripts function in script-loader.php. This is my theory anyways. I'm not familiar enough with the WordPress codebase to say for sure.

To recreate this issue, you can make a basic theme with an empty index.php, only the theme definition inside the style.css, an empty js file (to try to enqueue), and a functions.php that registers the hook.

<?php
// functions.php
add_filter( 'wp_video_shortcode_library', 'test_video_shortcode_library_enqueue_script' );
function test_video_shortcode_library_enqueue_script() {
        wp_enqueue_script( 'basic-video-shortcode', get_parent_theme_file_uri( '/media-test.js' ), array( ), '', true );
        return 'test_video_mejs';
}

The above worked before version 6.2, and the bug is still present in version 6.3. Downgrading back to 6.1.3 fixes the problem.

Change History (1)

#1 @ivanzhuck
16 months ago

@kevincorrigan, as a temporary solution you can add a condition which checks how many times the action 'wp_default_scripts' was called, like here:

add_filter('wp_video_shortcode_library', 'test_video_shortcode_library_enqueue_script');

function test_video_shortcode_library_enqueue_script()
{
	if (did_action( 'wp_default_scripts' ) === 1) {
		wp_enqueue_script('basic-video-shortcode', get_parent_theme_file_uri('/media-test.js'), array(), '', true);
	}

	return 'test_video_mejs';
}

Last edited 16 months ago by ivanzhuck (previous) (diff)
Note: See TracTickets for help on using tickets.