Make WordPress Core


Ignore:
Timestamp:
05/13/2024 10:37:38 PM (4 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/src/wp-includes/media.php

    r58110 r58143  
    21982198 */
    21992199function wp_iframe_tag_add_loading_attr( $iframe, $context ) {
    2200     /*
    2201      * Iframes with fallback content (see `wp_filter_oembed_result()`) should not be lazy-loaded because they are
    2202      * visually hidden initially.
    2203      */
    2204     if ( str_contains( $iframe, ' data-secret="' ) ) {
    2205         return $iframe;
    2206     }
    2207 
    22082200    /*
    22092201     * Get loading attribute value to use. This must occur before the conditional check below so that even iframes that
Note: See TracChangeset for help on using the changeset viewer.