Skip to content

Commit a8d146e

Browse files
westonruterclaude
andcommitted
Only print the expect link once the View Transitions style is printed.
Checking that the `wp-view-transitions-admin` style is `done` rather than merely enqueued ties the link to the CSS actually having been output in the head. If the style is enqueued too late, it is printed in the footer, and there is no transition at first render to wait for. Since the style is now only enqueued from admin-header.php, this check also leaves out iframe screens, so the `IFRAME_REQUEST` check is removed. It missed iframe screens that do not define that constant, such as the theme-information modal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2ba00cf commit a8d146e

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎src/wp-includes/view-transitions.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,18 @@ function wp_get_view_transitions_admin_css(): string {
4949
* query limits the first-render delay to when view transitions actually run, matching the
5050
* `@view-transition` rule in view-transitions.css.
5151
*
52-
* Nothing is printed when the admin View Transitions style is not enqueued, since there is then
53-
* no transition to wait for. Nothing is printed for iframe requests either, such as Thickbox
54-
* modals: they have no admin menu, and an `expect` link whose target never appears blocks the
55-
* first render until the whole document has been parsed.
52+
* Nothing is printed unless the admin View Transitions style has already been printed, since
53+
* there is otherwise no transition to wait for. That style is only enqueued from
54+
* wp-admin/admin-header.php, so this also leaves out iframe screens such as Thickbox modals,
55+
* which have no `#wpcontent`: an `expect` link whose target never appears blocks the first
56+
* render until the whole document has been parsed.
5657
*
5758
* @since 7.2.0
5859
*
5960
* @link https://html.spec.whatwg.org/multipage/links.html#link-type-expect
6061
*/
6162
function wp_print_view_transitions_render_blocking_link(): void {
62-
if ( ! wp_style_is( 'wp-view-transitions-admin' ) || defined( 'IFRAME_REQUEST' ) ) {
63+
if ( ! wp_style_is( 'wp-view-transitions-admin', 'done' ) ) {
6364
return;
6465
}
6566

‎tests/phpunit/tests/view-transitions/wpPrintViewTransitionsRenderBlockingLink.php‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function test_hook(): void {
5050
*/
5151
public function test_prints_render_blocking_link(): void {
5252
wp_enqueue_view_transitions_admin_css();
53+
get_echo( 'wp_print_styles', array( 'wp-view-transitions-admin' ) );
54+
$this->assertTrue( wp_style_is( 'wp-view-transitions-admin', 'done' ), 'Expected the style to have been printed.' );
55+
5356
$output = get_echo( 'wp_print_view_transitions_render_blocking_link' );
5457

5558
$processor = new WP_HTML_Tag_Processor( $output );
@@ -72,16 +75,16 @@ public function test_prints_nothing_when_style_not_enqueued(): void {
7275
}
7376

7477
/**
75-
* Tests that nothing is printed for an iframe request, which has no admin menu.
78+
* Tests that nothing is printed when the admin View Transitions style is enqueued but not yet printed.
7679
*
77-
* @ticket 65032
80+
* This happens when the style is enqueued too late for the head, so it is printed in the footer instead.
7881
*
79-
* @runInSeparateProcess
80-
* @preserveGlobalState disabled
82+
* @ticket 65032
8183
*/
82-
public function test_prints_nothing_for_iframe_request(): void {
83-
define( 'IFRAME_REQUEST', true );
84+
public function test_prints_nothing_when_style_not_printed(): void {
8485
wp_enqueue_view_transitions_admin_css();
86+
$this->assertTrue( wp_style_is( 'wp-view-transitions-admin' ), 'Expected the style to be enqueued.' );
87+
$this->assertFalse( wp_style_is( 'wp-view-transitions-admin', 'done' ), 'Expected the style to not be printed yet.' );
8588

8689
$this->assertSame( '', get_echo( 'wp_print_view_transitions_render_blocking_link' ) );
8790
}

0 commit comments

Comments
 (0)