Skip to content
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

Run template-part registration after all other blocks #3384

Conversation

ajlende
Copy link

@ajlende ajlende commented Sep 30, 2022

This is another (partial) alternative to #3352, #3359, and #3373.

This adjusts the priorities of block registration so that the core/template-part block is registered last. This means that all blocks (except core/template-part) will be registered before the metadata form get_blocks_metadata is called for the first time.

It currently has the problem that the block metadata for the core/template-part block itself won't be included, but that may be fixed with the combination of cache invalidation from #3373 if we can guarantee that register_block_core_template_part never unregisters any blocks.

I upped the WP_Block_Supports::init priority value to make room for blocks like core/post-comments to be registered after the rest of the core blocks, but before the core/template-part registration.

Trac ticket: https://core.trac.wordpress.org/ticket/56736


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Alex Lende added 3 commits October 5, 2022 13:52
Prioity 22 was chosen because register_legacy_post_comments_block is priority 21 and this should be called afterwards
This gives more breathing room for blocks that want to register themselves in a different order
@ockham ockham force-pushed the try/reprioritizing-block-registration-for-template-part-styles branch from 3da02d0 to f4f1bce Compare October 5, 2022 11:52
@ockham
Copy link
Contributor

ockham commented Oct 5, 2022

Rebased.

Comment on lines +252 to +256
/*
* This block relies on generated styles from previously registered blocks, so
* it should be registered last.
*/
add_action( 'init', 'register_block_core_template_part', 29 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that we'd need to make this change to the corresponding file in Gutenberg, since Core's build process uses the files from the @wordpress/block-library package as its source of truth for dynamic blocks' PHP code and overwrites any changes we make here 😬

(I think that's also the reason for the test failures we're seeing in CI.)

@ockham
Copy link
Contributor

ockham commented Oct 5, 2022

I'll change the Trac ticket linked in the PR desc to https://core.trac.wordpress.org/ticket/56736, since this PR would solve that, and the previously linked ticket (https://core.trac.wordpress.org/ticket/56644) has now been fixed.

@ajlende
Copy link
Author

ajlende commented Oct 10, 2022

Closing this out. Both related trac tickets have been solved.

@ajlende ajlende closed this Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants