Make WordPress Core


Ignore:
Timestamp:
05/13/2024 10:37:38 PM (6 weeks ago)
Author:
westonruter
Message:

Embeds: Enable lazy-loading of post embeds and fix keyboard a11y for hidden iframes.

Chrome unreliably loads a lazy-loaded iframe when it is hidden using clip: rect(1px, 1px, 1px, 1px). Instead of using clip, a lazy-loaded iframe can also be hidden with visibility:hidden which results in it loading not only in Chrome but all other browsers. With this change applied, the hard-coded check to prevent lazy-loading post embeds is now removed. An added benefit to using visibility:hidden is that the entire iframe in this case is not interactable, meaning that users navigating the document with the keyboard will not unexpectedly encounter tab stops inside of the hidden iframe, as can happen now with clip when the JS fails to reveal the loaded iframe. Note also that the clip property is deprecated.

Lastly, when such a post embed iframe is rendered in an RSS feed, the style attribute is now removed using the HTML Tag Processor as opposed to using string replacement.

Fixes #58773.
Props westonruter, joemcgill, swissspidy, joedolson, adamsilverstein.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r57987 r58143  
    32583258    /**
    32593259     * @ticket 52768
    3260      */
    3261     public function test_wp_iframe_tag_add_loading_attr_skip_wp_embed() {
     3260     * @ticket 58773
     3261     */
     3262    public function test_wp_iframe_tag_add_loading_attr_include_wp_embed() {
    32623263        $iframe   = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
    32633264        $fallback = '<blockquote>Fallback content.</blockquote>';
     
    32653266        $iframe   = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
    32663267
    3267         $this->assertStringNotContainsString( ' loading=', $iframe );
     3268        $this->assertStringContainsString( ' loading="lazy"', $iframe );
    32683269    }
    32693270
Note: See TracChangeset for help on using the changeset viewer.