-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Create block: Update template to use new performance tools for blocks coming in 6.7 #66485
base: trunk
Are you sure you want to change the base?
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 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. |
Size Change: 0 B Total Size: 1.81 MB ℹ️ View Unchanged
|
@@ -42,6 +42,14 @@ if ( ! defined( 'ABSPATH' ) ) { | |||
* @see https://developer.wordpress.org/reference/functions/register_block_type/ | |||
*/ | |||
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() { | |||
|
|||
// Register the block metadata. | |||
wp_register_block_metadata_collection( |
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 method will exist only in WordPress 6.7 so we would have to call it conditionally as long as the minimum required version for WP is set to 6.6.
By the way, @felixarntz opened a proposal https://core.trac.wordpress.org/ticket/62267 to add an option to this function to automatically register blocks listed in the manifest file. With that, we would no longer need to add register_block_type( __DIR__ . '/build' );
for every block type included in the plugin. Eventually (WordPress 6.8?), the following should become the only code required no matter how many block types the plugin contains:
// Registers the block types metadata.
wp_register_block_metadata_collection(
__DIR__ . '/build'
__DIR__ . '/build/blocks-manifest.php',
array( 'auto_register' => true )
);
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 method will exist only in WordPress 6.7 so we would have to call it conditionally as long as the minimum required version for WP is set to 6.6.
I'm sorry, I had added a check but didn't push up the changes. I went with a simple function_exists
call.
With that, we would no longer need to add register_block_type( DIR . '/build' ); for every block type included in the plugin.
That would be amazing. It's pretty easy to forget to go back and add that line for a new block.
Flaky tests detected in 9bbaa31. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11555971110
|
I need to investigate it further to understand better what happens when the block is located directly in the In effect, the manifest with block metadata puts the key for the block as Edit: I was wondering if that correctly loads the metadata from the cache file. It turns out that when I remove
|
Co-authored-by: Greg Ziółkowski <[email protected]>
There are two findings I have after playing with
|
What?
This PR adds the new
wp_register_block_metadata_collection()
function and associatednpm
commands to the standard template forcreate-block
.I've wrapped the
wp_register_block_metadata_collection
in afunction_exists
check so this could be merged before 6.7. but it's probably better to merge after it's releasedCloses #66484
Why?
Performance improvements are a good thing and by adding this to the template to new scaffolded blocks, extenders will get the benefits for all new blocks.
Testing Instructions
packages/create-block
node index.js new-block
new-block.php
filebuild-blocks-manifest
command and apostbuild
command that references it.