Skip to content

Conversation

@AnthonyLedesma
Copy link
Member

@AnthonyLedesma AnthonyLedesma commented Apr 6, 2023

Description

The many changes are a first pass to convert the blocks to register in PHP. The reason for this change has several benefits.
By registering in PHP

  • We can finally do the work to split our block code. That will lead to significant performance benefits.
  • This allows us to load several assets on-demand only when the related blocks are rendered. For example the lightbox, services-script, counter-script, gist-script, events-script, post-carousel-script, tiny-swiper-sciprs, masonry and animation scripts. While a number of these scripts had attempted to render 'per-block', in many cases the whole script would render regardless. This change aligns us with core practice in that regard.
  • It allows us to properly parse block attributes in various contexts. Previously, the server (PHP) had no knowledge of the block attributes which can affect block parsing in a number of ways including missing attributes.

Screenshots

Types of changes

How has this been tested?

Acceptance criteria

Checklist:

  • My code is tested
  • My code follows accessibility standards
  • My code has proper inline documentation
  • I've included any necessary tests
  • I've included developer documentation
  • I've added proper labels to this pull request

@AnthonyLedesma AnthonyLedesma added the [Status] Do Not Merge Issues/PRs that should not be merged (yet) label Apr 6, 2023
@AnthonyLedesma AnthonyLedesma self-assigned this Apr 6, 2023
@AnthonyLedesma AnthonyLedesma changed the title register all blocks php auto Register all blocks in PHP May 18, 2023
Copy link
Contributor

@olafleur-godaddy olafleur-godaddy left a comment

Choose a reason for hiding this comment

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

This is awesome work, good job!

registerBlockType( masonryName, { category: 'common', ...masonrySettings, ...v2Masonry } ); // Register masonry block
registerBlockType( offsetName, { category: 'common', ...offsetSettings, ...v2Offset } ); // Register offset block
registerBlockType( stackedName, { category: 'common', ...stackedSettings, ...v2Stacked } ); // Register stacked block
// const getV2Settings = ( blockMeta, blockSettings ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't need that code anymore, you can remove it ;)

public function coblocks_enqueue_scripts_for_core_blocks( $block_content, $block ) {

$block_name = $block['blockName'];
$block_attributes = $block['attrs'];
Copy link
Contributor

@olafleur-godaddy olafleur-godaddy Jul 11, 2023

Choose a reason for hiding this comment

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

I have a warning on the front page of my website :
Warning: Undefined array key "attrs" in /var/www/html/wp-content/plugins/coblocks/includes/class-coblocks-block-assets.php on line 519

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call! I've added some bail logic for if the block does not have attributes, or a name defined.

@AnthonyLedesma AnthonyLedesma merged commit ac4e3b6 into master Jul 12, 2023
@AnthonyLedesma AnthonyLedesma deleted the try-register-all-blocks branch July 12, 2023 19:50
@AnthonyLedesma AnthonyLedesma added this to the 3.1.0 milestone Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Do Not Merge Issues/PRs that should not be merged (yet)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants