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

Prevent usage of gutenberg_url in block-library #58242

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ function register_block_core_file() {
);

wp_register_script_module(
'@wordpress/block-library/file-block',
gutenberg_url( '/build/interactivity/file.min.js' ),
'@wordpress/block-library/file',
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/file.min.js' ) : includes_url( 'blocks/file/view.min.js' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking my understanding here. What's the long term vision for these wp_register_script_module calls? Are they going to be done automatically using block.json or if we need conditionals, maybe instead we should have generic calls like wp_hydrate_block( 'core/file' ) or something where the actual files are not hard-coded by guessed from block.json or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I remember @sirreal is working on a viewModule and viewScriptModule feature in block json. So should be done automatically.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. In the short term, we should replace them with viewScriptModule entries in the block.json. Then, at some point, I'd like to resume our work on behaviors where a single block can have a set of behaviors defined, and depending on the active ones, WordPress will enqueue the required JS and CSS files for those behaviors.

Copy link
Contributor

Choose a reason for hiding this comment

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

why not viewModule? or do we use that for something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

or viewScript?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the beginning, we called it the Modules API but then everything was renamed to "script modules":

Copy link
Member

Choose a reason for hiding this comment

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

Here's the viewScriptModule for Core: WordPress/wordpress-develop#5860

viewModule support was implemented in Gutenberg, but when "modules" became "script modules" in Core it seemed to make sense to align and use viewScriptModule, but that's still up for review.

array( '@wordpress/interactivity' ),
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
);
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function register_block_core_image() {

wp_register_script_module(
'@wordpress/block-library/image',
gutenberg_url( '/build/interactivity/image.min.js' ),
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/image.min.js' ) : includes_url( 'blocks/image/view.min.js' ),
array( '@wordpress/interactivity' ),
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
);
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,8 @@ function register_block_core_navigation() {
);

wp_register_script_module(
'@wordpress/block-library/navigation-block',
gutenberg_url( '/build/interactivity/navigation.min.js' ),
'@wordpress/block-library/navigation',
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/navigation.min.js' ) : includes_url( 'blocks/navigation/view.min.js' ),
array( '@wordpress/interactivity' ),
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
);
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function register_block_core_query() {

wp_register_script_module(
'@wordpress/block-library/query',
gutenberg_url( '/build/interactivity/query.min.js' ),
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/query.min.js' ) : includes_url( 'blocks/query/view.min.js' ),
array(
array(
'id' => '@wordpress/interactivity',
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ function register_block_core_search() {
);

wp_register_script_module(
'@wordpress/block-library/search-block',
gutenberg_url( '/build/interactivity/search.min.js' ),
'@wordpress/block-library/search',
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/search.min.js' ) : includes_url( 'blocks/search/view.min.js' ),
array( '@wordpress/interactivity' ),
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
);
Expand Down
Loading