Skip to content

Commit a72dbff

Browse files
authored
Enhance block registration by using blocks-manifest for improved performance (#76317)
1 parent 884c9e0 commit a72dbff

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎packages/create-block-interactive-template/index.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ module.exports = {
1818
viewScriptModule: 'file:./view.js',
1919
render: 'file:./render.php',
2020
example: {},
21+
folderName: './src/$slug',
2122
customScripts: {
22-
build: 'wp-scripts build --experimental-modules',
23-
start: 'wp-scripts start --experimental-modules',
23+
build: 'wp-scripts build --experimental-modules --blocks-manifest',
24+
start: 'wp-scripts start --experimental-modules --blocks-manifest',
2425
},
2526
},
2627
variants: {

‎packages/create-block-interactive-template/plugin-templates/$slug.php.mustache‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
if ( ! defined( 'ABSPATH' ) ) {
3838
exit; // Exit if accessed directly.
3939
}
40-
4140
/**
42-
* Registers the block using the metadata loaded from the `block.json` file.
43-
* Behind the scenes, it registers also all assets so they can be enqueued
41+
* Registers the block(s) metadata from the `blocks-manifest.php` and registers the block type(s)
42+
* based on the registered block metadata. Behind the scenes, it registers also all assets so they can be enqueued
4443
* through the block editor in the corresponding context.
4544
*
46-
* @see https://developer.wordpress.org/reference/functions/register_block_type/
45+
* @see https://make.wordpress.org/core/2025/03/13/more-efficient-block-type-registration-in-6-8/
46+
* @see https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/
4747
*/
4848
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
49-
register_block_type_from_metadata( __DIR__ . '/build' );
49+
wp_register_block_types_from_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' );
5050
}
5151
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );

0 commit comments

Comments
 (0)