[wp-trac] [WordPress Trac] #64150: Late-printed styles are not hoisted to HEAD if wp-block-library is not enqueued

WordPress Trac noreply at wordpress.org
Sat Oct 25 06:09:34 UTC 2025


#64150: Late-printed styles are not hoisted to HEAD if wp-block-library is not
enqueued
---------------------------+-------------------------
 Reporter:  westonruter    |      Owner:  westonruter
     Type:  defect (bug)   |     Status:  assigned
 Priority:  normal         |  Milestone:  6.9
Component:  Script Loader  |    Version:  trunk
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-------------------------
 This is a follow-up to #64099. In the [https://github.com/WordPress
 /wordpress-develop/pull/10288 PR], I raised a
 [https://github.com/WordPress/wordpress-
 develop/pull/10288#discussion_r2446753967 question] for future
 investigation:

 > There's one gotcha here which I want to investigate in a follow-up. It
 could be that a site doesn't use blocks at all, and they have removed this
 hook:
 >
 > `add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles'
 );`
 >
 > In this case, the style won't be present to add a placeholder to. This
 is likely exceedingly rare and an edge case that I don't think blocks the
 initial merge of this. But I want to follow on testing on a sites using
 the Classic Editor exclusively.

 Well, it wasn't so exceedingly rare, as @Soean
 [https://core.trac.wordpress.org/ticket/64099#comment:24 reported] this as
 a bug in 6.9-beta1:

 > we remove the `wp-block-library` styles from our site:
 >
 > {{{#!php
 > <?php
 > add_action(
 >       'enqueue_block_assets',
 >       function (): void {
 >               wp_deregister_style( 'wp-block-library' );
 >               wp_register_style( 'wp-block-library', '' );
 >       }
 > );
 > }}}
 >
 > Like others:
 > - https://github.com/search?q=wp_deregister_style%28+%27wp-block-
 library%27+%29%3B&type=code
 > - https://github.com/search?q=wp_dequeue_style%28+%27wp-block-
 library%27+%29&type=code
 >
 > With WP 6.9-Beta1 we don't get the `global-styles-inline-css` styles
 anymore, which breaks our styles.

 To reproduce this issue, you can install the following plugin:

 {{{#!php
 <?php
 /**
  * Plugin Name: Enqueue Stylesheet at WP Footer
  */

 add_action(
         'enqueue_block_assets',
         function (): void {
                 wp_deregister_style( 'wp-block-library' );
         }
 );

 add_action(
         'wp_head',
         static function () {
                 echo '<style>body { background-color: red; }</style>';
         }
 );

 add_action(
         'wp_footer',
         static function () {
                 wp_enqueue_style( 'lime-background', plugin_dir_url(
 __FILE__ ) . 'lime-background.css' );
         }
 );
 }}}

 The `lime-background.css` file contains simply:


 {{{#!css
 body {
         background-color: lime !important;
 }
 }}}

 When the plugin is active, a red background will appear because `lime-
 background` is printed at `wp_footer` with `print_late_styles()`, but
 since `wp-block-library` is not printed at `wp_head`, there is no
 placeholder comment in any the inline style for that stylesheet.

 We can address this issue simply by falling back to appending the late-
 printed styles to the very end of the `HEAD` tag.

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


More information about the wp-trac mailing list