-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ViewScriptModule: 6.5 compatibility changes #58832
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/compat/wordpress-6.5/scripts-modules.php ❔ lib/experimental/script-modules.php |
if ( empty( $module_asset_path ) ) { | ||
_doing_it_wrong( | ||
__FUNCTION__, | ||
sprintf( | ||
// This string is from WordPress Core. See `register_block_script_handle`. | ||
// Translators: This is a translation from WordPress Core (default). No need to translate. | ||
__( 'The asset file (%1$s) for the "%2$s" defined in "%3$s" block definition is missing.', 'default' ), | ||
$module_asset_raw_path, | ||
$field_name, | ||
$metadata['name'] | ||
), | ||
'6.5.0' | ||
); | ||
return false; | ||
} |
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.
In WordPress trunk we no longer require the asset file to be present.
$module_fields = array( | ||
// @todo remove viewModule support in Gutenberg >= 17.8 (replaced by viewScriptModule). | ||
'viewModule' => 'view_script_module_ids', | ||
'viewScriptModule' => 'view_script_module_ids', | ||
'viewModule' => 'view_script_module_ids', |
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.
This handles the deprecated viewModule
field. Core >= 6.5 handles viewScriptModule
.
register_rest_field( | ||
'block-type', | ||
'view_script_module_ids', | ||
array( | ||
'get_callback' => function ( $item ) { | ||
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $item['name'] ); | ||
if ( isset( $block_type->view_script_module_ids ) ) { | ||
return $block_type->view_script_module_ids; | ||
} | ||
return array(); | ||
}, | ||
) | ||
); |
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.
This is moved to trunk or the compat file.
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
4091040
to
f82922e
Compare
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.
LGTM
What?
viewScriptModule
block.json field support has landed in Core 6.5 (WordPress/wordpress-develop#5860 / https://core.trac.wordpress.org/changeset/57565).Move
viewScriptModule
support in Gutenberg to 6.5 compatibility.viewModule
support and theview_module_ids
REST API field are maintained in Gutenberg regardless of the WordPress version.Testing Instructions
Test with latest WordPress 6.4.3 and WordPress trunk. Try these steps with
viewModule
,viewScriptModule
and both.Add a block using
block.json
with a (viewModule
,viewScriptModule
, both) field pointing to its view module. I've compiled a block (with #57461) that's available at this gist. It can be unzipped as a plugin and used for testing.We should be able to add our block in the editor. If we use the REST API to query block types and search for
view_module_ids
andview_script_module_ids
we should find our block:If the block is added to a post and we visit it on the frontend, we should see it working as expected (a counter in our example).
We should also see the expected modules added to the importmap and module preloads on our post with the block. I used an older theme to ensure nothing else was enqueuing the interactivity module: