Repository navigation
Block Bindings: Support binding to innerBlocks (generic mechanism) - #79379
Closed
cbravobernal wants to merge 1 commit into
Closed
cbravobernal wants to merge 1 commit into
cbravobernal wants to merge 1 commit into
Conversation
cbravobernal
force-pushed
the
61225-innerblocks-bindings
branch
from
June 22, 2026 11:12
e77097a to
9f3f18c
Compare
cbravobernal
force-pushed
the
61225-innerblocks-bindings
branch
from
June 22, 2026 11:28
9f3f18c to
2ac2035
Compare
cbravobernal
force-pushed
the
61225-innerblocks-bindings
branch
2 times, most recently
from
July 3, 2026 11:02
001bff9 to
2529d3e
Compare
Extend the Block Bindings mechanism so a registered binding source can supply and receive a block's inner blocks (its child block tree), not just scalar attributes. Refs WordPress#61225. A block declares the binding with a reserved `innerBlocks` key inside `metadata.bindings` on the container that owns the inner blocks. The value contract is a single serialized block-markup string, parsed at each runtime boundary (`parse()` in JS, `parse_blocks()` in PHP): `undefined`/`null` falls back to the block's own serialized children, `''` is an intentionally-empty area, and a string is parsed into the controlled tree. No new source callbacks are introduced — the reserved key flows through the existing `getValues`/`setValues`/`canUserEditValue` (JS) and `get_value_callback` (PHP, read-only) API. This PR is the generic, source-agnostic mechanism only: - A generic injection seam in `useInnerBlocksProps` (`useBoundInnerBlocksProps`) that makes any locally-controlled container controlled when it declares the binding, reusing the controlled-inner-blocks engine (`useBlockSync`). Edits write back as one coherent undo level, and undo/redo of those edits is supported: the resolver skips a transient write that merely echoes the source's current value, and a bounded parse cache replays previously seen values with the same block identities so history steps do not remount the subtree. - Read-only enforcement: a source whose `canUserEditValue` (called with the binding's `args`) returns `false` locks the area structurally (`templateLock: 'all'`, no appender) and disables the editing mode of the bound subtree, rendering the child wrappers inert so content cannot be edited and silently dropped. - Release restores content: removing the binding, or a source flipping to absence, re-seeds the container with the last controlled tree instead of leaving it emptied by the controlled-sync teardown. - Recursion guards in both runtimes: a source supplying a block bound to itself (directly or through a cycle) resolves as absence — a bound ancestry context plus depth cap in the editor, a render stack keyed by (source, args) pushed on `render_block_data` and released on `render_block` on the server. - Server-side substitution on `render_block_data` (WordPress 7.1 compat) that replaces a bound block's inner blocks and rebuilds its `innerContent` template around the host's own static chunks, so the source tree renders in place with nested bindings resolved recursively. Top-level context mirrors core's `render_block()` setup, including the `render_block_context` filter. - `core/list-item` reconciliation: when a list item declares both a `content` and an `innerBlocks` binding, the shim's existing containment check prevents a double render on fixed cores, and on WP 6.9/7.0 — where applying the content binding wipes the `<li>` inner HTML — the shim restores the substituted children exactly as it restores a block's own. An example/test binding source (in the e2e plugins) exercises the read/write/read-only/absence paths without depending on any consumer. The first real consumer (`core/pattern-overrides`, an editable freeform area inside a synced pattern) and the user-facing documentation are intentionally NOT included here; they depend on a per-instance override storage model still under design and will follow separately. Covered by JS unit tests, PHP unit tests, and editor/frontend e2e tests (read, write-back, read-only locking and typing, detach, absence). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cbravobernal
force-pushed
the
61225-innerblocks-bindings
branch
from
July 3, 2026 15:09
2529d3e to
9e6c5e7
Compare
Contributor
Author
|
Superseded by #79852 — same commit, moved from the fork to a branch on this repository ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
🚧 Do not review yet — work in progress. This needs more input, more testing, and more knowledge-gathering before it is ready. I will mark it ready and request review when it is.
What?
Extends the Block Bindings mechanism so a registered binding source can supply and receive a block's inner blocks (its child block tree), not just scalar attributes.
Part of #61225. This PR is the generic, source-agnostic mechanism only — the first real consumer (
core/pattern-overrides) and the user-facing documentation are intentionally not included here (see "Scope" below).A block declares the binding with a reserved
innerBlockskey insidemetadata.bindings, on the container that owns the inner blocks:The value contract is a single serialized block-markup string, parsed at each runtime boundary (
parse()in JS,parse_blocks()in PHP):undefined(JS) /null(PHP)''No new source callbacks are introduced — the reserved key flows through the existing
getValues/setValues/canUserEditValue(JS, withcanUserEditValuereceiving the binding'sargs) andget_value_callback(PHP, read-only) API.Why?
Block Bindings could only bind scalar attributes. Many use cases need a source to own a block's child tree. This adds that capability generically, decoupled from any particular consumer.
How?
useInnerBlocksProps(useBoundInnerBlocksProps): makes any locally-controlled container controlled when it declares the binding, reusing the existing controlled-inner-blocks engine (useBlockSync).canUserEditValuereturnsfalselocks the area structurally (templateLock: 'all', no appender) and disables the editing mode of the bound subtree (the child wrappers render inert). Content in a read-only area cannot be edited at all — an edit that rendered but was dropped by the suppressed write-back would be silent data loss.(source, args)pushed onrender_block_dataand released onrender_block, plus_doing_it_wrong.render_block_data(WP 7.1 compat): replaces a bound block's inner blocks and rebuilds itsinnerContenttemplate around the host's own static chunks, so the source tree renders in place with nested bindings resolved recursively. Top-level context mirrors core'srender_block()setup, including therender_block_contextfilter.core/list-itemreconciliation: when a list item declares both acontentand aninnerBlocksbinding, the shim's existing containment check prevents a double render on fixed cores; on WP 6.9/7.0 — where applying the content binding wipes the whole<li>inner HTML — the shim restores the substituted children exactly as it restores a block's own.Scope — what is deliberately NOT here
core/pattern-overridesconsumer (editable freeform area in a synced pattern) and its synced-pattern editing carve-outs. It depends on a per-instance override storage model still under design: today it would serialize the edited subtree as a markup string into the placedcore/block'scontentattribute, which inflates (~2–4× via attribute escaping), duplicates per instance, and re-serializes the whole subtree per commit. That storage question is being worked separately before the consumer ships.onInput) currently serializes the full bound subtree per change to support echo suppression; on very large areas this could add typing latency. Tracked as a follow-up, entangled with the transient-write contract.Testing Instructions
innerBlockskey (or use the e2e example source inpackages/e2e-tests/plugins/block-bindings/).metadata.bindings.innerBlocks. Confirm the source-supplied children render in the editor and on the frontend, edits write back, undo/redo of those edits preserves selection, a read-only source locks the area (no appender, children inert — typing does nothing), removing the binding keeps the current children, and absence falls back to the block's own children.Automated coverage:
use-bound-inner-blocks): value contract, write-back/echo/undo guards,canUserEditValueargs, read-only subtree editing-mode enforcement, recursion-guard ancestry (including same-source-different-args composition), release-restores-content.phpunit/block-bindings-innerblocks-test.php,block-bindings-list-item-test.php): substitution, absence, empty area, static-chunk preservation, nested/recursive resolution, context inheritance (including viarender_block_context), recursion-guard termination and sequential-area release, list-item reconciliation including the WP 6.9/7.0 wiped-content restoration.block-bindings/inner-blocks.spec.js): editor+frontend read path, write-back, read-only (structure locked, children not selectable, typing produces no change), detach keeps content, absence fallback.🤖 Generated with Claude Code