Skip to content
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

Compat: Add DOMRect polyfill #20110

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function gutenberg_add_url_polyfill( $scripts ) {
gutenberg_register_vendor_script(
$scripts,
'wp-polyfill-url',
'https://unpkg.com/polyfill-library@3.26.0-0/polyfills/URL/polyfill.js',
'https://unpkg.com/polyfill-library@3.42.0/polyfills/URL/polyfill.js',
array(),
'3.26.0-0'
'3.42.0'
);

did_action( 'init' ) && $scripts->add_inline_script(
Expand All @@ -75,6 +75,49 @@ function gutenberg_add_url_polyfill( $scripts ) {
}
add_action( 'wp_default_scripts', 'gutenberg_add_url_polyfill', 20 );

/**
* Adds a polyfill for DOMRect in environments which do not support it.
*
* This can be removed when plugin support requires WordPress 5.4.0+.
*
* @see gutenberg_add_url_polyfill
* @see https://core.trac.wordpress.org/ticket/49360
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
* @see https://developer.wordpress.org/reference/functions/wp_default_packages_vendor/
*
* @since 7.5.0
*
* @param WP_Scripts $scripts WP_Scripts object.
*/
function gutenberg_add_dom_rect_polyfill( $scripts ) {
// Only register polyfill if not already registered. This prevents handling
// in an environment where core has updated to manage the polyfill. This
// depends on the action being handled after default script registration.
$is_polyfill_script_registered = (bool) $scripts->query( 'wp-polyfill-dom-rect', 'registered' );
if ( $is_polyfill_script_registered ) {
return;
}

gutenberg_register_vendor_script(
$scripts,
'wp-polyfill-dom-rect',
'https://unpkg.com/polyfill-library@3.42.0/polyfills/DOMRect/polyfill.js',
array(),
'3.42.0'
);

did_action( 'init' ) && $scripts->add_inline_script(
'wp-polyfill',
wp_get_script_polyfill(
$scripts,
array(
'window.DOMRect' => 'wp-polyfill-dom-rect',
)
)
);
}
add_action( 'wp_default_scripts', 'gutenberg_add_dom_rect_polyfill', 20 );

/**
* Sets the current post for usage in template blocks.
*
Expand Down