Docs: clarify what an empty parent array means during block registration - #81525
Docs: clarify what an empty parent array means during block registration#81525Kgupta62 wants to merge 1 commit into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Kgupta62, @cguntur, @hardiks010. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
What?
Closes #15731
Documents what an empty
parentarray means during block registration, and corrects the property's documented type.Why?
The issue asks for the behaviour to be spelled out, and notes that
Type: Arrayisn't quite right and that the default is unclear. The assumption in the issue — that an empty array restricts a block to the root — is the opposite of what actually happens, which is a good reason to write it down.How?
canInsertBlockTypepassesblockType.parenttocheckAllowList, which for an array returnslist.includes( item ). For[]that is alwaysfalse, including at the root where the item isnull. Insertion is then only permitted when a container explicitly allows the block through its ownallowedBlocks(hasParentAllowedBlock === true). So:[]→ matches no parent, including the root, so the block cannot be inserted anywhere and does not show in the inserter, unless a container lists it inallowedBlocks.Documented that in
block-metadata.mdandblock-registration.md, changed the documented type fromArraytostring[], noted the default, and mirrored the clarification in theblock.jsonschema description and theBlockTypetype's doc comment.Documentation only — no behaviour change.
Testing Instructions
parent: [], then search for it in the inserter at the root and inside a Group — it is offered in neither. AddallowedBlocks: [ 'your/block' ]to a container and it becomes insertable there.npm run docs:build(ornpm run docs:check-api-docs-unstaged) should report no changes to regenerate.Testing Instructions for Keyboard
n/a — documentation only.
Use of AI Tools
AI tooling (Claude Code) was used while investigating the issue and drafting the wording. I traced the behaviour through
canInsertBlockType/checkAllowListmyself before documenting it, and take responsibility for the content of this PR.