-
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
Inserter: Fix Block visibility manager #65700
Conversation
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. |
Size Change: +831 B (+0.05%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
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.
For example, even if I hide all blocks in the Text category via "Manage block visibility", only the List item block will be displayed in The text category in the inserter. This happens with other categories as well. I think this is because the Block Manager filters out blocks that have parents.
This behavior seems a bit strange, but what do you think?
I agree, It seems if the blocks that have a "parent" block are not allowed, their children shouldn't be allowed either. |
It should be fixed now. |
It seems like e2e tests and unit tests are failing. Maybe it has to do with the logic in |
This should be ready now. |
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.
Looks good to me 👍
Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
This reverts commit d83720c.
Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
|
||
// If parent blocks are not visible, child blocks should be hidden too. | ||
if ( !! blockType.parent?.length ) { | ||
return blockType.parent.some( |
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.
At this point, how do we know blockType.parent
is an array? Can't it be a string, for example, that also has a length
property?
For context, I'm looking at an issue in the support forum that I believe to be related to this check: the report is recent, the users report issues when inserting blocks, and there's no other place in the codebase that uses parent.some
.
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.
Looking at the block registration, it seems parent
should be null or an array, but we don't enforce that.
Even the recently added logic to block registration doesn't check that parent is an array. This:
if (
1 === settings?.parent?.length &&
name === settings.parent[ 0 ]
) { /**/ }
would still be fine for blocks that register parent
as a string.
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.
One thing we can do to fix this is to make the if check above explicit for what we want to do: verify that it is an array and that it has elements.
The more general question is: how parent
can become an array? Are block authors mis-registering this property? Can we now enforce it being an array?
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.
PR at #66234
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.
Even the recently added logic to block registration doesn't check that parent is an array.
Regarding this conditional statement, I suggested a change in this comment. However, I noticed that, unlike my comment, the order of each conditional was reversed when it was merged, which is certainly not what was intended.
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.
cc @gziolo for thoughts about enforcing the blockType.parent
being an array at registration. Would that be feasible?
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 are discussing it in this thread: #66234 (comment). The short answer is if we know that block types were registered with the parent
set to a string, the best way would be to respect that and provide a fallback handling.
Closes #65687
What?
In #65490 we changed a bit how the inserter works by avoiding any initial block type filtering and only upon insertion figuring out what things can or can't be allowed in a given position and also try to guess a more suitable position.
The problem is that in some situations (block visibility managed, allowed blocks settings), it doesn't really make sense to show the blocks at all. So this PR separate the
canInsertBlock
selector into two:Note
For child blocks, I elected for now to keep them in the inserter. The reason is that there's value in that, for instance, if you're within a nested block within a column, it's handy to be able to click "column" block to insert a new column in the parent's columns block. We can revise/tweak that behavior if it's deemed too problematic.
Note that the PR applies the fix to the pattern inserter too.
Testing Instructions
1- Open the post inserter
2- Go to preferences > blocks and remove the "heading" block
3- Open the inserter and notice the block is not visible anymore and any block that uses the block is not either.