-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate Safari Rerenders into one script #49215
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,23 +187,42 @@ private static function get_css_custom_property_declaration( $filter_data ) { | |
* Safari renders elements incorrectly on first paint when the SVG filter comes after the content that it is filtering, | ||
* so we force a repaint with a WebKit hack which solves the issue. | ||
* | ||
* @param string $selector The selector to apply the hack for. | ||
* @param string $selectors The CSS selectors to apply the hack for. | ||
*/ | ||
private static function safari_rerender_hack( $selector ) { | ||
private static function safari_rerender_hack( $selectors ) { | ||
/* | ||
* Simply accessing el.offsetHeight flushes layout and style | ||
* Accessing el.offsetHeight flushes layout and style | ||
* changes in WebKit without having to wait for setTimeout. | ||
*/ | ||
printf( | ||
'<script>( function() { var el = document.querySelector( %s ); var display = el.style.display; el.style.display = "none"; el.offsetHeight; el.style.display = display; } )();</script>', | ||
wp_json_encode( $selector ) | ||
'<script> | ||
( | ||
function() { | ||
%s.forEach( selector => { | ||
document.querySelectorAll( selector ).forEach( function( el ) { | ||
if( ! el ) { | ||
return; | ||
} | ||
var display = el.style.display; | ||
el.style.display = "none"; | ||
el.offsetHeight; | ||
el.style.display = display; | ||
} ); | ||
} ); | ||
} | ||
)(); | ||
</script>', | ||
wp_json_encode( $selectors ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. II think this will be easier to review if we leave it expanded, and then instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
); | ||
} | ||
|
||
/** | ||
* Outputs all necessary SVG for duotone filters, CSS for classic themes, and safari rerendering hack | ||
*/ | ||
public static function output_footer_assets() { | ||
|
||
$selectors = array(); | ||
|
||
foreach ( self::$output as $filter_data ) { | ||
|
||
// SVG will be output on the page later. | ||
|
@@ -216,10 +235,12 @@ public static function output_footer_assets() { | |
wp_add_inline_style( 'core-block-supports', 'body{' . self::get_css_custom_property_declaration( $filter_data ) . '}' ); | ||
} | ||
|
||
global $is_safari; | ||
if ( $is_safari ) { | ||
self::safari_rerender_hack( $filter_data['selector'] ); | ||
} | ||
$selectors[] = $filter_data['selector']; | ||
} | ||
|
||
global $is_safari; | ||
if ( $is_safari && ! empty( $selectors ) ) { | ||
self::safari_rerender_hack( $selectors ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered using |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed "Simply" for inclusion and brevity sake.