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

Block Hooks API: Update Navigation block feature gate #58388

Merged

Conversation

tjcafferkey
Copy link
Contributor

@tjcafferkey tjcafferkey commented Jan 29, 2024

What?

Updates the feature gate for usage of the Block Hooks API to insert inner blocks into the core Navigation block.

Why?

We were previously checking for get_hooked_blocks to gate this feature against WordPress 6.3 and below, however this feature also depends upon the metadata ignoredHookedBlocks functionality to work correctly which isn't present within WordPress 6.4, resulting in a bug surfacing itself.

How?

I've updated the feature gate to check for the function responsible for the ignoredHookedBlocks logic that we need, which prevents this running on WP 6.4 until compat code is ported over.

Testing Instructions

On WP 6.4

  1. Add the below code to your themes function file and check on the frontend and within the Editor that the Search block does not get inserted into your Navigation

On WP 6.5 Beta

  1. Add the below code to your themes functions file to register the core/search block as an inner block
  2. Load header template part, change the width of the Search block and save template part
  3. Load frontend and check that only 1 Search block is rendered.
function register_navigation_last_child( $hooked_blocks, $position, $anchor_block, $context ) {
	if ( $anchor_block === 'core/navigation' && $position === 'last_child' ) {
		$hooked_blocks[] = 'core/search';
	}

	return $hooked_blocks;
}

add_filter( 'hooked_block_types', 'register_navigation_last_child', 10, 4 );

@tjcafferkey tjcafferkey added [Type] Bug An existing feature does not function as intended [Block] Navigation Affects the Navigation Block labels Jan 29, 2024
@tjcafferkey tjcafferkey self-assigned this Jan 29, 2024
@tjcafferkey tjcafferkey changed the title Update the feature gate to check for the presence of function get_hoo… Block Hooks API: Update Navigation block feature gate Jan 29, 2024
Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@ockham
Copy link
Contributor

ockham commented Jan 29, 2024

@c4rl0sbr4v0 We'd like to include this in GB 17.6. Should we cherry-pick to the release/17.6 branch (after merging to trunk, of course), or would you prefer doing that yourself? 😊

(Edit: No need for a separate RC, IMO.)

@ockham ockham added this to the Gutenberg 17.6 milestone Jan 29, 2024
@ockham ockham added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jan 29, 2024
Copy link

Flaky tests detected in d62993a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7698726773
📝 Reported issues:

@tjcafferkey tjcafferkey merged commit 7e7f042 into trunk Jan 29, 2024
56 checks passed
@tjcafferkey tjcafferkey deleted the fix/feature-gating-navigation-block-hooks-compatibility-bug branch January 29, 2024 16:23
@cbravobernal
Copy link
Contributor

cbravobernal commented Jan 29, 2024

Hi @ockham

With the label is enough, I will do a RC3 tomorrow (for other PRs 😅 ), not this one.

@cbravobernal
Copy link
Contributor

I just cherry-picked this PR to the release/17.6 branch to get it included in the next release: 8a7d26b

@cbravobernal cbravobernal removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jan 30, 2024
ockham added a commit that referenced this pull request Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants