Skip to content

Docs: clarify what an empty parent array means during block registration - #81525

Open
Kgupta62 wants to merge 1 commit into
WordPress:trunkfrom
Kgupta62:docs/15731-empty-parent-array
Open

Docs: clarify what an empty parent array means during block registration#81525
Kgupta62 wants to merge 1 commit into
WordPress:trunkfrom
Kgupta62:docs/15731-empty-parent-array

Conversation

@Kgupta62

Copy link
Copy Markdown
Contributor

What?

Closes #15731

Documents what an empty parent array 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: Array isn'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?

canInsertBlockType passes blockType.parent to checkAllowList, which for an array returns list.includes( item ). For [] that is always false, including at the root where the item is null. Insertion is then only permitted when a container explicitly allows the block through its own allowedBlocks (hasParentAllowedBlock === true). So:

  • omitted → no parent restriction;
  • [] → 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 in allowedBlocks.

Documented that in block-metadata.md and block-registration.md, changed the documented type from Array to string[], noted the default, and mirrored the clarification in the block.json schema description and the BlockType type's doc comment.

Documentation only — no behaviour change.

Testing Instructions

  1. Read the changed sections and check they match the behaviour described above.
  2. To confirm the behaviour itself: register a test block with parent: [], then search for it in the inserter at the root and inside a Group — it is offered in neither. Add allowedBlocks: [ 'your/block' ] to a container and it becomes insertable there.
  3. npm run docs:build (or npm 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/checkAllowList myself before documenting it, and take responsibility for the content of this PR.

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

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.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Blocks.

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.

@github-actions github-actions Bot added the [Package] Blocks /packages/blocks label Aug 12, 2026
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Unlinked Accounts

The 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.

Unlinked contributors: Kgupta62, cguntur, hardiks010.

Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: sagarsdeshmukh <sagardeshmukh@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Blocks /packages/blocks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation: Clarify the behavior of parent when empty during block registration

1 participant