<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[61076] trunk: Script Loader: Fall back to hoisting late-printed styles to end of `HEAD` if `wp-block-library` is not enqueued.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/61076">61076</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/61076","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2025-10-28 05:32:13 +0000 (Tue, 28 Oct 2025)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Script Loader: Fall back to hoisting late-printed styles to end of `HEAD` if `wp-block-library` is not enqueued.

When the `wp-block-library` stylesheet is not enqueued, there will be no associated inline style present. This inline style normally contains the placeholder CSS comment for the HTML Tag Processor to identify the token after which the late-printed styles should be inserted. However, when the `wp-block-library` stylesheet is not enqueued (such as in themes which do not use blocks), or else the inline style is not printed for whatever reason, this adds a fallback to insert the late-printed styles immediately before `</head>`. This ensures that late-printed styles will always get hoisted.  

Developed in https://github.com/WordPress/wordpress-develop/pull/10417

Follow-up to <a href="https://core.trac.wordpress.org/changeset/61008">[61008]</a>.

Props westonruter, peterwilsoncc, Soean.
See <a href="https://core.trac.wordpress.org/ticket/64099">#64099</a>, <a href="https://core.trac.wordpress.org/ticket/43258">#43258</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/64150">#64150</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
<li><a href="#trunktestsphpunitteststemplatephp">trunk/tests/phpunit/tests/template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesscriptloaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php   2025-10-27 21:07:47 UTC (rev 61075)
+++ trunk/src/wp-includes/script-loader.php     2025-10-28 05:32:13 UTC (rev 61076)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3593,13 +3593,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Load separate block styles so that the large block-library stylesheet is not enqueued unconditionally,
-        * and so that block-specific styles will only be enqueued when they are used on the page.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * If the theme supports block styles, add filters to ensure they are loaded separately and on demand. Without this,
+        * if a theme does not want or support block styles, then enabling these filters can result in undesired separate
+        * block-specific styles being enqueued, though a theme may also be trying to nullify the wp-block-library
+        * stylesheet.
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        add_filter( 'should_load_separate_core_block_assets', '__return_true', 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( current_theme_supports( 'wp-block-styles' ) ) {
+               /*
+                * Load separate block styles so that the large block-library stylesheet is not enqueued unconditionally,
+                * and so that block-specific styles will only be enqueued when they are used on the page.
+                */
+               add_filter( 'should_load_separate_core_block_assets', '__return_true', 0 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Also ensure that block assets are loaded on demand (although the default value is from should_load_separate_core_block_assets).
-       add_filter( 'should_load_block_assets_on_demand', '__return_true', 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Also ensure that block assets are loaded on demand (although the default value is from should_load_separate_core_block_assets).
+               add_filter( 'should_load_block_assets_on_demand', '__return_true', 0 );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Add hooks which require the presence of the output buffer. Ideally the above two filters could be added here, but they run too early.
</span><span class="cx" style="display: block; padding: 0 10px">        add_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3684,33 +3692,50 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        };
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Loop over STYLE tags.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        while ( $processor->next_tag( array( 'tag_name' => 'STYLE' ) ) ) {
-                               // Skip to the next if this is not the inline style for the wp-block-library stylesheet (which contains the placeholder).
-                               if ( 'wp-block-library-inline-css' !== $processor->get_attribute( 'id' ) ) {
-                                       continue;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 while ( $processor->next_tag( array( 'tag_closers' => 'visit' ) ) ) {
+
+                               // We've encountered the inline style for the 'wp-block-library' stylesheet which probably has the placeholder comment.
+                               if (
+                                       ! $processor->is_tag_closer() &&
+                                       'STYLE' === $processor->get_tag() &&
+                                       'wp-block-library-inline-css' === $processor->get_attribute( 'id' )
+                               ) {
+                                       // If the inline style lacks the placeholder comment, then we have to continue until we get to </HEAD> to append the styles there.
+                                       $css_text = $processor->get_modifiable_text();
+                                       if ( ! str_contains( $css_text, $placeholder ) ) {
+                                               continue;
+                                       }
+
+                                       // Remove the placeholder now that we've located the inline style.
+                                       $processor->set_modifiable_text( str_replace( $placeholder, '', $css_text ) );
+                                       $buffer = $processor->get_updated_html();
+
+                                       // Insert the $printed_late_styles immediately after the closing inline STYLE tag. This preserves the CSS cascade.
+                                       $span   = $processor->get_span();
+                                       $buffer = implode(
+                                               '',
+                                               array(
+                                                       substr( $buffer, 0, $span->start + $span->length ),
+                                                       $printed_late_styles,
+                                                       substr( $buffer, $span->start + $span->length ),
+                                               )
+                                       );
+                                       break;
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // If the inline style lacks the placeholder comment, then something went wrong and we need to abort.
-                               $css_text = $processor->get_modifiable_text();
-                               if ( ! str_contains( $css_text, $placeholder ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // As a fallback, append the hoisted late styles to the end of the HEAD.
+                               if ( $processor->is_tag_closer() && 'HEAD' === $processor->get_tag() ) {
+                                       $span   = $processor->get_span();
+                                       $buffer = implode(
+                                               '',
+                                               array(
+                                                       substr( $buffer, 0, $span->start ),
+                                                       $printed_late_styles,
+                                                       substr( $buffer, $span->start ),
+                                               )
+                                       );
</ins><span class="cx" style="display: block; padding: 0 10px">                                         break;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                               // Remove the placeholder now that we've located the inline style.
-                               $processor->set_modifiable_text( str_replace( $placeholder, '', $css_text ) );
-                               $buffer = $processor->get_updated_html();
-
-                               // Insert the $printed_late_styles immediately after the closing inline STYLE tag. This preserves the CSS cascade.
-                               $span   = $processor->get_span();
-                               $buffer = implode(
-                                       '',
-                                       array(
-                                               substr( $buffer, 0, $span->start + $span->length ),
-                                               $printed_late_styles,
-                                               substr( $buffer, $span->start + $span->length ),
-                                       )
-                               );
-                               break;
</del><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        return $buffer;
</span></span></pre></div>
<a id="trunktestsphpunitteststemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/template.php    2025-10-27 21:07:47 UTC (rev 61075)
+++ trunk/tests/phpunit/tests/template.php      2025-10-28 05:32:13 UTC (rev 61076)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,6 +78,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        protected $original_wp_styles;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * @var array|null
+        */
+       protected $original_theme_features;
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function set_up() {
</span><span class="cx" style="display: block; padding: 0 10px">                parent::set_up();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->original_default_mimetype = ini_get( 'default_mimetype' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -110,6 +115,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_styles                 = null;
</span><span class="cx" style="display: block; padding: 0 10px">                wp_scripts();
</span><span class="cx" style="display: block; padding: 0 10px">                wp_styles();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->original_theme_features = $GLOBALS['_wp_theme_features'];
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function tear_down() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -117,6 +124,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_scripts = $this->original_wp_scripts;
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_styles  = $this->original_wp_styles;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $GLOBALS['_wp_theme_features'] = $this->original_theme_features;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 ini_set( 'default_mimetype', $this->original_default_mimetype );
</span><span class="cx" style="display: block; padding: 0 10px">                unregister_post_type( 'cpt' );
</span><span class="cx" style="display: block; padding: 0 10px">                unregister_taxonomy( 'taxo' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -913,46 +922,76 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Tests that wp_load_classic_theme_block_styles_on_demand() does not add hooks for classic themes when output buffering is blocked.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Data provider.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @ticket 64099
-        * @covers ::wp_load_classic_theme_block_styles_on_demand
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @return array<string, array{theme: string, set_up: Closure|null, expected_on_demand: bool, expected_buffer_started: bool}>
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_wp_load_classic_theme_block_styles_on_demand_in_classic_theme_but_output_buffering_blocked(): void {
-               add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_false' );
-               switch_theme( 'default' );
-
-               wp_load_classic_theme_block_styles_on_demand();
-
-               $this->assertFalse( has_filter( 'should_load_separate_core_block_assets' ), 'Expect should_load_separate_core_block_assets filter NOT to be added for block themes.' );
-               $this->assertFalse( has_filter( 'should_load_block_assets_on_demand', '__return_true' ), 'Expect should_load_block_assets_on_demand filter NOT to be added for block themes.' );
-               $this->assertFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expect wp_template_enhancement_output_buffer_started action NOT to be added for block themes.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function data_wp_load_classic_theme_block_styles_on_demand(): array {
+               return array(
+                       'block_theme'                                => array(
+                               'theme'                   => 'block-theme',
+                               'set_up'                  => static function () {},
+                               'expected_on_demand'      => false,
+                               'expected_buffer_started' => false,
+                       ),
+                       'classic_theme_with_output_buffer_blocked'   => array(
+                               'theme'                   => 'default',
+                               'set_up'                  => static function () {
+                                       add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_false' );
+                               },
+                               'expected_on_demand'      => false,
+                               'expected_buffer_started' => false,
+                       ),
+                       'classic_theme_with_block_styles_support'    => array(
+                               'theme'                   => 'default',
+                               'set_up'                  => static function () {
+                                       add_theme_support( 'wp-block-styles' );
+                               },
+                               'expected_on_demand'      => true,
+                               'expected_buffer_started' => true,
+                       ),
+                       'classic_theme_without_block_styles_support' => array(
+                               'theme'                   => 'default',
+                               'set_up'                  => static function () {
+                                       remove_theme_support( 'wp-block-styles' );
+                               },
+                               'expected_on_demand'      => false,
+                               'expected_buffer_started' => true,
+                       ),
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Tests that wp_load_classic_theme_block_styles_on_demand() adds the expected hooks for classic themes.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Tests that wp_load_classic_theme_block_styles_on_demand() adds the expected hooks (or not).
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 64099
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 64150
+        *
</ins><span class="cx" style="display: block; padding: 0 10px">          * @covers ::wp_load_classic_theme_block_styles_on_demand
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         *
+        * @dataProvider data_wp_load_classic_theme_block_styles_on_demand
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_wp_load_classic_theme_block_styles_on_demand_in_classic_theme(): void {
-               switch_theme( 'default' );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_wp_load_classic_theme_block_styles_on_demand( string $theme, ?Closure $set_up, bool $expected_on_demand, bool $expected_buffer_started ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( wp_should_load_separate_core_block_assets(), 'Expected wp_should_load_separate_core_block_assets() to return false initially.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertFalse( wp_should_load_block_assets_on_demand(), 'Expected wp_should_load_block_assets_on_demand() to return true' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expected wp_template_enhancement_output_buffer_started action to be added for classic themes.' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                switch_theme( $theme );
+               if ( $set_up ) {
+                       $set_up();
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_load_classic_theme_block_styles_on_demand();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( wp_should_load_separate_core_block_assets(), 'Expected wp_should_load_separate_core_block_assets() filters to return true' );
-               $this->assertTrue( wp_should_load_block_assets_on_demand(), 'Expected wp_should_load_block_assets_on_demand() to return true' );
-               $this->assertNotFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expected wp_template_enhancement_output_buffer_started action to be added for classic themes.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( $expected_on_demand, wp_should_load_separate_core_block_assets(), 'Expected wp_should_load_separate_core_block_assets() return value.' );
+               $this->assertSame( $expected_on_demand, wp_should_load_block_assets_on_demand(), 'Expected wp_should_load_block_assets_on_demand() return value.' );
+               $this->assertSame( $expected_buffer_started, (bool) has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expected wp_template_enhancement_output_buffer_started action added status.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Data provider.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @return array<string, array{set_up?: Closure}>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @return array<string, array{set_up: Closure|null}>
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function data_wp_hoist_late_printed_styles(): array {
</span><span class="cx" style="display: block; padding: 0 10px">                return array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -975,6 +1014,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        remove_action( 'wp_footer', 'wp_print_footer_scripts' );
</span><span class="cx" style="display: block; padding: 0 10px">                                },
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'block_library_removed'           => array(
+                               'set_up' => static function () {
+                                       wp_deregister_style( 'wp-block-library' );
+                               },
+                       ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1006,9 +1050,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Simulate wp_head.
</span><span class="cx" style="display: block; padding: 0 10px">                $head_output = get_echo( 'wp_head' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $placeholder_pattern = '#/\*wp_late_styles_placeholder:[a-f0-9-]+\*/#';
-
-               $this->assertMatchesRegularExpression( $placeholder_pattern, $head_output, 'Expected the placeholder to be present' );
</del><span class="cx" style="display: block; padding: 0 10px">                 $this->assertStringContainsString( 'early', $head_output, 'Expected the early-enqueued stylesheet to be present.' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Enqueue a late style (after wp_head).
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1024,7 +1065,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Apply the output buffer filter.
</span><span class="cx" style="display: block; padding: 0 10px">                $filtered_buffer = apply_filters( 'wp_template_enhancement_output_buffer', $buffer );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertDoesNotMatchRegularExpression( $placeholder_pattern, $filtered_buffer, 'Expected the placeholder to be removed.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertStringContainsString( '</head>', $buffer, 'Expected the closing HEAD tag to be in the response.' );
+
+               $this->assertDoesNotMatchRegularExpression( '#/\*wp_late_styles_placeholder:[a-f0-9-]+\*/#', $filtered_buffer, 'Expected the placeholder to be removed.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $found_styles = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'HEAD' => array(),
</span><span class="cx" style="display: block; padding: 0 10px">                        'BODY' => array(),
</span></span></pre>
</div>
</div>

</body>
</html>