Webfonts: increase priority of init hook to account for block reregistration#41569
Merged
ramonjd merged 2 commits intoJun 7, 2022
Merged
Conversation
…Resolver_Gutenberg::get_merged_data()`, which instantiates `WP_Theme_JSON_Gutenberg()`; Gutenberg server-side blocks are registered via the init hook with a priority value of `20`. E.g., `add_action( 'init', 'register_block_core_image', 20 )`; This priority value is added dynamically during the build. See: tools/webpack/blocks.js. We want to make sure Gutenberg blocks are re-registered before any Theme_JSON operations take place so that we have access to updated merged data.
aaronrobertshaw
approved these changes
Jun 7, 2022
aaronrobertshaw
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix @ramonjd 🎉
✅ Tested re-registration of blocks by updating the image block to have an __experimentalSelector and opting into expanded border support. Works well.
✅ Tested successfully following the instructions on the original Webfonts PR.
LGTM! 🚢
Contributor
|
Added the Needs Dev Note label in case this needs a dev note (either individual or as part of a "misc" dev note) for WP 6.1 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #41296 (I think)
What?
Webfonts are registered via the
inithook at the highest priority.Gutenberg server-side blocks are registered via the
inithook with a priority value of20. E.g.,add_action( 'init', 'register_block_core_image', 20 );This priority value is added dynamically during the build. See: tools/webpack/blocks.js.
gutenberg_register_webfonts_from_theme_json()callsWP_Theme_JSON_Resolver_Gutenberg::get_merged_data(),which instantiates
WP_Theme_JSON_Gutenberg();Unfortunately this happens before Gutenberg server-side blocks are re-registered, therefore any plugin-only updates to block.json for example do not appear in the theme.json merged data.
Why?
We want to make sure Gutenberg blocks are re-registered before any Theme_JSON operations take place so that we have access to updated merged data.
How?
Bumping priority from
20to21:add_action( 'init', 'gutenberg_register_webfonts_from_theme_json', 21 );Testing Instructions
Add an
__experimentalSelectorproperty to a block in its block.json file:Check that the selector is registered in get_blocks_metadata
And that blocks load as per normal 😄
Go through the test steps on the original webfonts PR: