[wp-trac] [WordPress Trac] #58759: Iframed block editor breaks printing some pre-registered scripts enqueued late

WordPress Trac noreply at wordpress.org
Sat Jul 8 02:56:29 UTC 2023


#58759: Iframed block editor breaks printing some pre-registered scripts enqueued
late
--------------------------+-----------------------------
 Reporter:  aaemnnosttv   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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
 <?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)**
 [[Image(posts.jpg)]]

 **Block editor (no 404 and error in query monitor – script not printed)**
 [[Image(block-editor.jpg)]]

 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58759>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list