woocommerce icon indicating copy to clipboard operation
woocommerce copied to clipboard

Build and register a block metadata collection in one file for enhanced performance

Open mreishus opened this issue 1 year ago • 7 comments

Take advantage of https://core.trac.wordpress.org/changeset/59132 - "Editor: Allow registering PHP manifest file for block metadata collections for enhanced performance."

  • Adds a new ./assets/client/blocks/blocks-json.php to the built version of the plugin, that compiles all of the block.json files into one php file.
  • Calls the new wp_register_block_metadata_collection() to register the file, such that subsequent calls to register_block_from_metadata don't need to read and parse each individual block.json file.

To test:

  • Make sure to test with WordPress 6.7 Beta 1 or later.
    • function_exists( 'wp_register_block_metadata_collection' ) will return true if this condition is met.
  • All blocks should continue to work the same in the editor and in the frontend.
  • In wp-includes/src, add logging to `register_block_type_from_metadata() near the top:
	if ( $registry_metadata ) {
		$metadata = $registry_metadata;
		error_log("Registering without decoding: $file_or_folder");
	} elseif ( $metadata_file_exists ) {
		$metadata = wp_json_file_decode( $metadata_file, array( 'associative' => true ) );
		error_log("Need to decode: $file_or_folder");
	} else {
		$metadata = array();
	}

Check the log and we should see all the woocommerce blocks no longer needing to wp_json_file_decode().

mreishus avatar Sep 05 '24 23:09 mreishus