-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Hooks: Fix in Navigation block #59021
Conversation
FYI @gziolo |
@@ -1383,7 +1383,7 @@ function block_core_navigation_get_most_recently_published_navigation() { | |||
* @param WP_Post $post `wp_navigation` post object corresponding to the block. | |||
* @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any. | |||
*/ | |||
function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) { | |||
function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post, $callback = 'insert_hooked_blocks' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name (block_core_navigation_insert_hooked_blocks
) isn't quite accurate anymore since it can now either insert hooked blocks, or set the ignoredHookedBlocks
metadata.
Furthermore, requiring the callback name as an arg here is also possibly exposing too many internals.
Not sure if we want two separate functions (maybe using the same underlying helper, just with different callbacks?), e.g. block_core_navigation_insert_hooked_blocks
and block_core_navigation_set_ignored_hooked_blocks_metadata
or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 43a9276
There is still a small bit of code duplication by creating the visitor functions which in theory could be abstracted, but I think having it this way is more clear. Of course, open to opposing opinions on that.
@@ -1441,6 +1440,10 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) { | |||
} | |||
update_post_meta( $post->ID, '_wp_ignored_hooked_blocks', json_encode( $ignored_hooked_blocks ) ); | |||
} | |||
|
|||
// TODO: wp_update_post() to set the post_content to the updated markup (to include the ignoredHookedBlocks metadata). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I.e. for anchor blocks other than the mock root Nav block -- in case a block hooks e.g. after
core/page-list
, we want the ignoredHookedBlocks
metadata set on that anchor block, in the markup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to think of it, we should ideally cover that case with a unit test somewhere 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9da0b54
Flaky tests detected in 894d356fc64b4c7b35a1e664067754c95e421399. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7930437803
|
@ockham I've also updated the feature gate to be |
*/ | ||
function block_core_navigation_remove_serialized_parent_block( $serialized_block ) { | ||
$start = strpos( $serialized_block, '-->' ) + strlen( '-->' ); | ||
$end = strrpos( $serialized_block, '<!--' ); | ||
return substr( $serialized_block, $start, $end - $start ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were already doing this logic here. I've just moved it into its own function to reuse.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Thank you for your work @tjcafferkey! My plan is to land this today 🙂 @youknowriad @getdave It'd be great to get this into WP 6.5 Beta 2. What's your ETA for the package sync? 😊 |
894d356
to
6423090
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some creative work there to account for the fact that the content of the Navigation block doesn't contain the parent block wrapper 👍🏻
I think we had the wrong label on this one 😅 |
Update the Block Hooks mechanism as used in the Navigation block upon writing the REST API response received from a client to the DB. The Block Hooks mechanism recently underwent some overhaul (in WordPress/wordpress-develop#6087), which decoupled hooked block injection from setting the `ignoredHookedBlocks` metadata. The latter is no longer done by `insert_hooked_blocks` but by a separate function called `set_ignored_hooked_blocks_metadata` (that can be passed as a callback to the `make_{before|after}_block` visitor factories). Since the implementation of the Navigation block relied on the previous functionality, it needs to be updated to work properly: We need to run block tree traversal with `set_ignored_hooked_blocks_metadata` rather than `insert_hooked_blocks` on the template content received from the endpoint for the Navigation post type, upon persisting to the DB. Co-authored-by: ockham <bernhard-reiter@git.wordpress.org> Co-authored-by: tjcafferkey <tomjcafferkey@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
I just cherry-picked this PR to the cherry-pick-beta-2 branch to get it included in the next release: 302d96f |
Update the Block Hooks mechanism as used in the Navigation block upon writing the REST API response received from a client to the DB. The Block Hooks mechanism recently underwent some overhaul (in WordPress/wordpress-develop#6087), which decoupled hooked block injection from setting the `ignoredHookedBlocks` metadata. The latter is no longer done by `insert_hooked_blocks` but by a separate function called `set_ignored_hooked_blocks_metadata` (that can be passed as a callback to the `make_{before|after}_block` visitor factories). Since the implementation of the Navigation block relied on the previous functionality, it needs to be updated to work properly: We need to run block tree traversal with `set_ignored_hooked_blocks_metadata` rather than `insert_hooked_blocks` on the template content received from the endpoint for the Navigation post type, upon persisting to the DB. Co-authored-by: ockham <bernhard-reiter@git.wordpress.org> Co-authored-by: tjcafferkey <tomjcafferkey@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
Note that this revert PR did not make it into the 17.7 release. However, it is in 17.8 RC1 and will be include in the 17.8 release next week. |
This PR caused this issue: #59516 I don't understand why. |
What?
Update the Block Hooks mechanism as used in the Navigation block upon writing the REST API response received from a client to the DB.
Why?
The Block Hooks mechanism recently underwent some overhaul (in WordPress/wordpress-develop#6087), which decoupled hooked block injection from setting the
ignoredHookedBlocks
metadata. The latter is no longer done byinsert_hooked_blocks
but by a separate function calledset_ignored_hooked_blocks_metadata
(that can be passed as a callback to themake_{before|after}_block
visitor factories).Since the implementation of the Navigation block relied on the previous functionality, it needs to be updated to work properly.
How?
We need to run block tree traversal with
set_ignored_hooked_blocks_metadata
rather thaninsert_hooked_blocks
on the template content received from the endpoint for the Navigation post type, upon persisting to the DB.Testing Instructions
Verify that with current Core
trunk
, current versions of GB don't work properly w.r.t. hooked blocks insertion into the Navigation block (specifically when making changes to the Nav block).functions.php
block.json
file and retest starting from step 2.