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

Remove unnecessary code for ensuring interactivity dependency in block core functions #6354

Conversation

michalczaplinski
Copy link
Contributor

@michalczaplinski michalczaplinski commented Apr 3, 2024

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.

Copy link

github-actions bot commented Apr 3, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props czapla, gziolo, shailu25, cbravobernal.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Apr 3, 2024

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@@ -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.
Copy link
Member

@gziolo gziolo Apr 4, 2024

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.

Copy link
Member

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' ) );

Copy link
Member

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?

Copy link
Contributor Author

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)?

Copy link
Member

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.

Copy link
Member

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
Copy link
Contributor Author

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)

Copy link
Member

@gziolo gziolo May 20, 2024

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.

Copy link
Contributor

@cbravobernal cbravobernal left a 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.

@gziolo
Copy link
Member

gziolo commented May 20, 2024

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 wp-interactivity was used as a dependent script handle. In the current shape of PR, such custom scripts won't get printed on the site. It will prevent potential JS errors, but it will also prevent enqueuing execution of the custom JavaScript. I performed a quick search in the WPDirectory:

wp-interactivity in Plugins: https://www.wpdirectory.net/search/01HYB6GR4B51Y9Q52DQQEHJ03F
wp-interactivity in Themes: https://www.wpdirectory.net/search/01HYB6JDD4TG7V67ME7P77B9NN

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 wp-interactivity script handle.

@gziolo
Copy link
Member

gziolo commented Jun 4, 2024

@gziolo gziolo closed this Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants