Make WordPress Core

Opened 15 months ago

#58759 new defect (bug)

Iframed block editor breaks printing some pre-registered scripts enqueued late

Reported by: aaemnnosttv's profile aaemnnosttv Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.3
Component: Editor Keywords:
Focuses: Cc:

Description

https://core.trac.wordpress.org/changeset/56047/ changed the way scripts are loaded in the block editor which can have unexpected consequences for scripts that otherwise load successfully in other areas of wp-admin. This changeset broke enqueuing pre-registered scripts by handle, if the scripts were also registered beforehand.

The following code can be used to demonstrate:

<?php

function register_my_script() {
    wp_register_script( 'test-script', '/foo.js' );
}
add_action( 'admin_enqueue_scripts', 'register_my_script' );
add_action( 'wp_enqueue_scripts', 'register_my_script' );

add_action( 'wp_print_scripts', function () {
    wp_enqueue_script( 'test-script' );
} );

The script is printed successfully globally across the site (wp-admin + front), including the editor in 6.2 and before.

Posts screen (404 shows script was printed)

Block editor (no 404 and error in query monitor – script not printed)

Tested using revision 56164 as can be seen in the screenshot.

Note, that the same script if registered on init instead is printed successfully in the block editor and Query Monitor shows the same "missing dependency" error. This shows that the change does not affect all pre-registered scripts but there is a matter of timing involved. Nonetheless, the above used to work so it is a breaking change.

Attachments (2)

posts.jpg (203.2 KB) - added by aaemnnosttv 15 months ago.
block-editor.jpg (509.8 KB) - added by aaemnnosttv 15 months ago.

Download all attachments as: .zip

Change History (2)

Note: See TracTickets for help on using tickets.