-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 toggle #57956
Block Hooks: Fix toggle #57956
Conversation
@@ -83,7 +83,7 @@ function BlockHooksControlPure( { name, clientId } ) { | |||
} | |||
|
|||
const hookedBlock = candidates?.find( | |||
( candidate ) => name === candidate.name | |||
( candidate ) => candidate.name === block.name |
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.
In case of before
and after
insertion, all children of the current anchor block's parent are candidates; we need to compare them to the hooked block's name (block.name
), rather than the anchor block's name
(which will always be true, as the anchor block is of course also a child of its own parent).
Size Change: +4 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Flaky tests detected in 90e112d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7568838568
|
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.
Good catch, @ockham!
What?
Fix the Block Hooks toggle (broken by #56862 (comment)).
Why?
After #56862, the Block Hooks toggle stopped working properly:
If you had one instance of a hooked block that was inserted
before
ofafter
its anchor block in your template, it became impossible to use the toggle to remove the block -- it would just stay enabled. (You could only delete the block manually.)If you had additional instances of hooked blocks, the behavior would be even weirder: Even if you deleted the hooked block, the toggle would stay enabled.
How?
By fixing a check that was using the wrong variable to compare to.
Testing Instructions
To reproduce the issue (on
trunk
):Now manually delete the other Like Button (in the Comments Template block) to test the scenario with only one hooked block.
To verify the fix
On this branch, go through the above instructions again. Verify that the buggy behavior (marked ❌ ) has been fixed.
Note that importantly, some of the "fixed" behavior is still counter-intuitive: If both instances of the Like Button block (i.e. below Post Content and in Comment Template) were present in the first place, disabling the Like Button toggle for the Post Content will cause the toggle to disappear altogether. This is currently expected behavior; it will be fixed separately by #57928.
Screenshots or screencast