Inserter: Fix handling of child blocks#23231
Conversation
|
Size Change: -54 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
| <ChildBlocks | ||
| rootClientId={ rootClientId } | ||
| // Pass along every block, as getInserterItems() will have | ||
| // already filtered out non-child blocks. |
There was a problem hiding this comment.
This comment makes me wonder what's special about ChildBlocks component. Why not just render BlockTypesList directly?
There was a problem hiding this comment.
They receive different visual treatments.
Here's ChildBlocks:
Here's InserterPanel:
Perhaps we should unify the two? I'd rather address this as a separate issue, though.
In the meantime I agree that ChildBlocks should at least work the same as InserterPanel where the parent is responsible for passing through BlockTypes. I've changed that in 866b98e2f4.
There was a problem hiding this comment.
Yes, seems like unnecessary complexity for now. I believe the visual difference is from the old design.
talldan
left a comment
There was a problem hiding this comment.
Looks like a good solution.
I'm surprised this problem hasn't had more consequences, it'd be interesting to know the history and whether this was a recently introduced bug.
It was probably introduced in #20880, but I haven't confirmed that. I'd not be surprised if no third parties are using this functionality since it's not very well documented and we don't (yet) use it ourselves! |
When a block C specifies `parent: [ P ]`, it means that C may only be
added to P. It does NOT mean that P may *only* contain C. (Which is what
`<InnerBlocks allowedBlocks={ [ C ] }>` means.)
This fixes the Inserter so that the correct blocks are shown when
inserting into a block that is referenced by `parent`. It does so by
leaning on `getInserterItems()` which does the right thing.
0cad806 to
8b5ca5a
Compare


Fixes #23227. Necessary for #22656.
When a block C specifies
parent: [ P ], it means that C may only be added to P. It does NOT mean that P may only contain C. (Which is what<InnerBlocks allowedBlocks={ [ C ] }>means.)This fixes the Inserter so that the correct blocks are shown when inserting into a block that is referenced by
parent. It does so by leaning ongetInserterItems()which already does the right thing.To test
Paste the following snippet into the DevTools console:
Snippet
The Paragraph, Image and Add to Cart blocks should appear in the Inserter.