Skip to content
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
17 changes: 16 additions & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,23 @@ function gutenberg_default_script_modules() {
break;
}

/*
* All script modules in Gutenberg are (currently) related to the Interactivity API which prioritizes server-side rendering.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's @wordpress/a11y module that's not strictly an iAPI concept.

https://make.wordpress.org/core/2024/10/14/updates-to-script-modules-in-6-7/

I don't think other modules have been introduced, but I could have missed something. Should a11y be low as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly, but it is only used by the interactivity-router, right? And it is used as a dynamic import, so it exists exclusively in the importmap and so there is no fetchpriority to print.

Granted, it could end up getting added as a static dependency. If I try doing that, I see that with this Gutenberg PR it is printed with fetchpriority=low, but if I try WP Core trunk then it omits fetchpriority (so it is auto).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this in 1ab3c34.

And in core, I've addressed in WordPress/wordpress-develop#9770 via WordPress/wordpress-develop@e2d4676

* Therefore, the modules should be fetched with a low priority to avoid network contention with any LCP element resource.
* For allowing a block to opt-in to another fetchpriority, see <https://github.com/WordPress/gutenberg/issues/71366>.
*
* 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(
'fetchpriority' => 'low',
);

$path = gutenberg_url( "build-module/{$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 ); // The $args parameter is new as of WP 6.9 per <https://core.trac.wordpress.org/ticket/61734>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked to make sure extra arguments to functions don't cause errors/warnings/notices and that does seem to be the case 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, adding extra arguments is fine. No complaints going back even to PHP 4.3: https://3v4l.org/doYun

Any additional unnamed params could be obtained by the function via func_get_args().

}
}
remove_action( 'wp_default_scripts', 'wp_default_script_modules' );
Expand Down
Loading