-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Remove unnecessary code for ensuring interactivity dependency in block core functions #6354
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
@@ -281,10 +281,6 @@ function wp_default_packages_scripts( $scripts ) { | |||
*/ | |||
$assets = include ABSPATH . WPINC . "/assets/script-loader-packages{$suffix}.php"; | |||
|
|||
// Add the private version of the Interactivity API manually. |
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.
I hope we can safely remove it fully as it was very hard to use private version of Interactivity API. Technically speaking, folks were able to list is as a dependency so this needs to be investigated carefully.
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.
You can keep the script handle for backward compatibility and skip the file reference this way:
$scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) ); |
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.
The simple way to test it, would be to see what happens when a script defines wp-interactivity-api
as a dependency with the changes applied. Does it still enqueue?
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.
I'll test it.
To be clear: with the changes in the current PR, I expect that it should not enqueue the Interactivity API. Are you saying that it should still enqueue the it (for backward compat)?
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.
No, I’m only talking about verifying that scripts that depend on the wp-interactivity-api script handle continue to enqueue. The example presents how to define a script handle without any file on the disk referenced.
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.
I recorded a video to illustrate the potential problem better:
Screen.Recording.2024-05-20.at.16.12.30.mov
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.
ok, I've just tested it and it was never possible for scripts to depend on wp-interactivity
in the first place because wp-interactivity
is an ES module.
I tried enqueuing a script like:
function my_custom_scripts() {
wp_register_script(
'my-custom-script',
includes_url() . '/js/my-custom-script.js',
array('wp-interactivity'),
'1.0.0',
true
);
wp_enqueue_script('my-custom-script');
}
add_action('wp_enqueue_scripts', 'my_custom_scripts');
it will enqueue both my-custom-script
& wp-interactivity
as scripts (not script modules) which results in:
Uncaught SyntaxError: Unexpected token 'export' (at index.min.js?ver=1a0bf353a1bf8c59d31b:2070:1)
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.
It doesn't look like the private version of Interactivity API was exposed as ES Module in WordPress 6.4:
https://github.com/WordPress/WordPress/blob/6.4-branch/wp-includes/js/dist/interactivity.js
It's a regular script that exposes the webpack chunk under __WordPressPrivateInteractivityAPI__
global.
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.
I guess this concern https://github.com/WordPress/wordpress-develop/pull/6354/files#r1550930263 will not apply now that developer's just need to use WP 6.5 for the Interactivity API and we are close to the 6.6 release.
See the video included in #6354 (comment). It all depends on whether
It looks like there should be nothing to worry about. so either way is fine with the consequences described above if any script for any reason depends on |
Committed with https://core.trac.wordpress.org/changeset/58322. |
I'm removing old code for registering the private version of the Interactivity API pre-6.5.
The Interactivity API is being loaded as a script module as of WordPress 6.5.
I've removed the bodies of the previously deprecated functions, now no-ops, since the scripts are being registered as modules here. These functions remain because they were public, but their execution is unnecessary.
Trac ticket: https://core.trac.wordpress.org/ticket/60913#ticket
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.