wip
This commit is contained in:
@@ -35,6 +35,7 @@ function wp_script_modules(): WP_Script_Modules {
|
||||
* identifier has already been registered.
|
||||
*
|
||||
* @since 6.5.0
|
||||
* @since 6.9.0 Added the $args parameter.
|
||||
*
|
||||
* @param string $id The identifier of the script module. Should be unique. It will be used in the
|
||||
* final import map.
|
||||
@@ -60,9 +61,15 @@ function wp_script_modules(): WP_Script_Modules {
|
||||
* It is added to the URL as a query string for cache busting purposes. If $version
|
||||
* is set to false, the version number is the currently installed WordPress version.
|
||||
* If $version is set to null, no version is added.
|
||||
* @param array $args {
|
||||
* Optional. An array of additional args. Default empty array.
|
||||
*
|
||||
* @type bool $in_footer Whether to print the script module in the footer. Only relevant to block themes. Default 'false'. Optional.
|
||||
* @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional.
|
||||
* }
|
||||
*/
|
||||
function wp_register_script_module( string $id, string $src, array $deps = array(), $version = false ) {
|
||||
wp_script_modules()->register( $id, $src, $deps, $version );
|
||||
function wp_register_script_module( string $id, string $src, array $deps = array(), $version = false, array $args = array() ) {
|
||||
wp_script_modules()->register( $id, $src, $deps, $version, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,6 +79,7 @@ function wp_register_script_module( string $id, string $src, array $deps = array
|
||||
* will be registered.
|
||||
*
|
||||
* @since 6.5.0
|
||||
* @since 6.9.0 Added the $args parameter.
|
||||
*
|
||||
* @param string $id The identifier of the script module. Should be unique. It will be used in the
|
||||
* final import map.
|
||||
@@ -97,9 +105,15 @@ function wp_register_script_module( string $id, string $src, array $deps = array
|
||||
* It is added to the URL as a query string for cache busting purposes. If $version
|
||||
* is set to false, the version number is the currently installed WordPress version.
|
||||
* If $version is set to null, no version is added.
|
||||
* @param array $args {
|
||||
* Optional. An array of additional args. Default empty array.
|
||||
*
|
||||
* @type bool $in_footer Whether to print the script module in the footer. Only relevant to block themes. Default 'false'. Optional.
|
||||
* @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional.
|
||||
* }
|
||||
*/
|
||||
function wp_enqueue_script_module( string $id, string $src = '', array $deps = array(), $version = false ) {
|
||||
wp_script_modules()->enqueue( $id, $src, $deps, $version );
|
||||
function wp_enqueue_script_module( string $id, string $src = '', array $deps = array(), $version = false, array $args = array() ) {
|
||||
wp_script_modules()->enqueue( $id, $src, $deps, $version, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +183,31 @@ function wp_default_script_modules() {
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* The Interactivity API is designed with server-side rendering as its primary goal, so all of its script modules
|
||||
* should be loaded with low fetchpriority and printed in the footer since they should not be needed in the
|
||||
* critical rendering path. Also, the @wordpress/a11y script module is intended to be used as a dynamic import
|
||||
* dependency, in which case the fetchpriority is irrelevant. See <https://make.wordpress.org/core/2024/10/14/updates-to-script-modules-in-6-7/>.
|
||||
* However, in case it is added as a static import dependency, the fetchpriority is explicitly set to be 'low'
|
||||
* since the module should not be involved in the critical rendering path, and if it is, its fetchpriority will
|
||||
* be bumped to match the fetchpriority of the dependent script.
|
||||
*/
|
||||
$args = array();
|
||||
if (
|
||||
str_starts_with( $script_module_id, '@wordpress/interactivity' ) ||
|
||||
str_starts_with( $script_module_id, '@wordpress/block-library' ) ||
|
||||
'@wordpress/a11y' === $script_module_id
|
||||
) {
|
||||
$args['fetchpriority'] = 'low';
|
||||
$args['in_footer'] = true;
|
||||
}
|
||||
|
||||
// Marks all Core blocks as compatible with client-side navigation.
|
||||
if ( str_starts_with( $script_module_id, '@wordpress/block-library' ) ) {
|
||||
wp_interactivity()->add_client_navigation_support_to_script_module( $script_module_id );
|
||||
}
|
||||
|
||||
$path = includes_url( "js/dist/script-modules/{$file_name}" );
|
||||
wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'] );
|
||||
wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'], $args );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user