-
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
InnerBlocks' allowedBlocks
whitelist not respected due to parent
field of another block's block.json
.
#32436
Comments
block.json
.allowedBlocks
whitelist not respected due to parent
field of another block's block.json
.
@talldan Might you have 5mins to verify this? It would be much appreciated. I suspect this is the core reason why we are using block filters to manually force the available blocks for the Nav Editor. |
In my understanding, the gist of the above is that allowed blocks should have more strength than parent. I 100% think you're right to expect so as well, since:
If a parent specification overrides the allowed blocks specification it has high chances to crash the parent. If the allowed blocks overrides the parent nothing breaks (if the only available parent of block x does not allow block x, nothing breaks, it's a small bug). |
I believe you are correct 👍
Also Indeed it specifically tests for hasBlockSupport( blockType, 'inserter', true ) ) In which case I think we should rename the method as I took it to mean "tell me which blocks are allowed to be inserted into the editor in general". |
What is the difference between blocks allowed in the inserter and blocks allowed to be inserted in a block? I think I get the answer but we may need to spell it out. Do we need hidden blocks? If so, what is the difference between hidden and not allowed? |
It's worth considering how plugins might work. A block might have a setting for So I think the current behaviour is correct. Making It's been mentioned before that
Yeah, I've mentioned before this could be renamed and stabilised, but it slips my mind now what a good name would be - #25786 (comment) (cc @draganescu). |
I'm thinking this might be just a limitation of the block supports API (ie: it's not filterable)? It feels like we're allowing Should we instead look at if/how we can make the Block Supports API more extensible for Plugin developers? Indeed I see some overlap here with |
I'm not sure, it seems a bit of an existential question—if It might also be difficult to change the order of precedence now, because it'd be a breaking change.
There have been some past issues about extending
Possibly a few duplicate issues, and worth searching for others that I didn't catch. |
This isn't a question I can answer at this point so closing for now. |
Description
The
<InnerBlocks>
API enables a developer to provide a whitelist ofallowedBlocks
which should determine which blocks are allowed to be inserted as child blocks.A good example of this is the
core/navigation
block which defines anALLOWED_LIST
as a constant.However, currently on
trunk
if a child block defines aparent
in itsblock.json
then it will always be available as an "allowed block type" even if the parent block has excluded it from the allowed blocks.The reason for this appears to be the
canInsertBlockTypeUnmemozied
selectorgutenberg/packages/block-editor/src/store/selectors.js
Lines 1324 to 1353 in 6da0390
Essentially the current logic allows a block to be available if either:
<InnerBlock>
'sallowedBlocks
.parent
field of itsblock.json
.As a result, even if
#1
is false, if#2
is true then the block will be made available despite the fact that the parent's block list settings explicitly defined that it should not be available.For an example see the
core/navigation-link
block which definescore/navigation
as aparent
block in itsblock.json
.Steps to reproduce
You can test the problem for yourself.
trunk
.core/navigation
block'sedit.js
and replacegutenberg/packages/block-library/src/navigation/edit.js
Lines 32 to 39 in 6da0390
with
This should mean that only spacer and search blocks are allowed as child blocks of Navigation.
npm run dev
.Expected behaviour
If a given block A defines a set of
allowedBlocks
and passes that to<InnerBlocks>
then only those blocks should be available as "allowed blocks" even if another block B defines block A as aparent
inblock.json
.Actual behaviour
If a block defines another block as a
parent
viablock.json
then it will always be available even if the other block excludes it from theallowedBlocks
list of<InnerBlocks>
.Screenshots or screen recording (optional)
Code snippet (optional)
WordPress information
Device information
The text was updated successfully, but these errors were encountered: