Repository navigation
Block Bindings: Render innerBlocks bindings on the server - #85568
cbravobernal wants to merge 41 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 2.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. ⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
d047fd6 to
b3462ce
Compare
b3462ce to
bba9715
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Source sanitization bypasses custom-CSS restrictions, and replacement placement breaks legacy Group inner containers.
2 open issues
What changed in this PR
Adds experimental server-side innerBlocks bindings for Group and Column blocks, laying the groundwork for source-driven block content while leaving editor behavior unchanged.
Changes:
- Replaces inner blocks with sanitized source markup, supporting empty values and fallback content.
- Removes nested bindings that could cause recursive expansion.
- Adds experiment registration, conditional loading, and PHP tests.
| File | Description |
|---|---|
phpunit/experimental/block-bindings-inner-blocks-test.php |
Tests replacement, fallback, sanitization, and recursion prevention. |
phpunit/bootstrap.php |
Enables the experiment for PHP tests. |
lib/load.php |
Loads the implementation when the experiment is enabled. |
lib/experimental/experiments/load.php |
Registers the Inner blocks bindings experiment. |
lib/experimental/block-bindings-inner-blocks.php |
Implements source-driven inner-block rendering. |
Review effort: Balanced
ab294f6 to
62c9907
Compare
9768551 to
7f4ddfd
Compare
c9be6da to
56757c0
Compare
…n blocks. A block bindings source can now supply the inner blocks of a Group or Column block through `metadata.bindings.innerBlocks`. The value is serialized block markup, which replaces the block's own inner blocks before they render. An empty string leaves the block without inner blocks, and any other value keeps its own. The markup is sanitized with `wp_kses_post()`, as bound rich text already is, and its custom CSS is removed. Supplied blocks can't bind their own inner blocks, so that sources can't expand each other forever. The editor isn't offered `innerBlocks` yet, as it doesn't render these bindings. Backports WordPress/gutenberg#85568. Fixes #66415. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49d8f80 to
ce47303
Compare
…, compare requests regardless of key order, and place inner blocks in the last element. Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCeAisD5bTZvgFGutfYV55
…up and Column blocks. The editor settings filter removed `innerBlocks` from every block type, so a block that added it through `block_bindings_supported_attributes` lost it in the editor. It now touches only the two block types this file adds the attribute to. A test registers such a block and checks that the editor still offers it. Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…tead of a regex handler. The embed test registered an embed handler with a regular expression. The `[embed]` shortcode and the bare URL both reach `wp_oembed_get()`, whose `pre_oembed_result` filter returns the test iframe before any provider lookup, so the test no longer needs one. Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…r now. The code stays behind the gutenberg-inner-blocks-bindings experiment and moves to Core later, so the backport changelog entry goes until then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCeAirDCWdozxoHFnEH9Jg
… is sanitized. wp_kses_post() already sanitizes block attribute values through wp_pre_kses_block_attributes(), including HTML escaped inside the JSON (\u003c...\u003e). The test pins that guarantee for inner blocks bindings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCeAirDCWdozxoHFnEH9Jg
Inner blocks bindings is headed to Core, and its Core PR can stay open while the plugin side lands behind the experiment. This reverts commit 05545c3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCeAirDCWdozxoHFnEH9Jg
Six tests left the inner blocks bindings budget spent above zero. The feature resets it when the outermost bound block renders, so no test was affected, but unsetting both globals starts each test from the same state as a fresh page load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCeAirDCWdozxoHFnEH9Jg
…at threw. A bound block that throws while rendering never reaches the `render_block` filter, so it stays tracked. Walking `debug_backtrace()` on every inner blocks resolution to repair this was costly and fragile, for a case that only matters when something catches the exception and keeps rendering. Accept it until the Core backport, where `WP_Block::render()` can stop tracking the block in a `finally` block: the request keeps its own inner blocks for the rest of the page load, and nothing loops or renders unsanitized because of it. The test now pins that behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e0383d1 to
d2d81c3
Compare
…s, and spell out the budget cost of a caught exception. The escaped HTML test used a literal `<`, which the test above it already covers. Use the `<` form that `serialize_blocks()` writes, and fail if `className` is dropped instead of sanitized. After a caught exception every later bound block counts as nested, so once the budget is spent the rest of the page keeps its own inner blocks. Say so in the docblock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re PR, add `@since`, and test the untested paths. - Add `@since 7.3.0` to every function and a note on where the code goes in Core. - Rename four functions to match the methods in the Core PR. - Say that any block can add `innerBlocks` through `block_bindings_supported_attributes`, and test it. - Test values that are not strings, a legacy Group with text after its inner container, and markup without an element or that ends inside a comment. - Unregister the test block types and sources in `tear_down()`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…arkup. The test rendered a Group without a name or pattern overrides context, so the source returned null and the test passed even without the check that only the block's own binding replaces its inner blocks. Give the Group a name and override content with block markup, and assert the source returned it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…accept. A top-level supplied block fails when the bound block's `allowedBlocks` (block type or attribute) leaves it out, or when its own `parent` or `ancestor` leaves out the bound block. One failure rejects the whole value and the fallback inner blocks render. Nested blocks aren't checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llowed blocks check. The allowed blocks check skipped every supplied chunk without a block name, so a bound block with `allowedBlocks` rendered loose HTML it would reject as a block. HTML outside any block now counts as `core/freeform`, unless it is only whitespace. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…get. A value the allowed blocks check rejects doesn't count against `block_bindings_inner_blocks_budget`, so a later allowed value at the same budget still renders. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Active issues reject valid ancestor-constrained blocks, incorrectly discard distinct block-type responses as recursion, and prevent default-priority source-value filters from replacing supplied inner blocks.
3 open issues
Review effort: Balanced
| $context[ $context_name ] = $block_instance->context[ $context_name ]; | ||
| } | ||
| } | ||
| $request = array( $source_name, $source_args, $context, $block_instance->attributes ); |
There was a problem hiding this comment.
Fixed in bcfe959. The request now includes the block name, with a test for two block types that share binding and attributes.
| foreach ( array( $block_type->parent, $block_type->ancestor ) as $allowed_parents ) { | ||
| if ( is_array( $allowed_parents ) && ! in_array( $block_instance->name, $allowed_parents, true ) ) { |
There was a problem hiding this comment.
This is on purpose for now. The server only knows the bound block, not the blocks above it, so a block whose ancestor names one of those is rejected and the Group keeps its own blocks. It fails safe, and the description says so.
…ks-bindings-server
…ace inner blocks after the other source value filters. A source can return other inner blocks for another block type, so two block types with the same binding and attributes are no longer the same request. The replacement now runs last on `block_bindings_source_value`, so a filter with the default priority can change the supplied inner blocks. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… calls. A block bindings source call is one use of a source by a bound block: the source, the binding's arguments, the context the source uses, and the block's name and attributes. Also update the comments that described Core's WP_Block changes, since Core now uses the same functions through filters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The source call and the check against the source calls rendering move into gutenberg_block_bindings_replace_inner_blocks(), and finding the wrapper closer moves into gutenberg_block_bindings_split_at_wrapper_closer(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the allowedBlocks, parent and ancestor check (saved post content isn't checked either), the block_bindings_inner_blocks_budget filter (the budget stays at 100), and the special case for empty legacy Groups. Find the wrapper closer in one loop, shorten the docblocks, and merge the value contract tests into data providers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es not support. Removes the null check after `WP_HTML_Processor::create_fragment()`, which never returns null for a string in the default context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


What?
Part of #61225. Behind the
gutenberg-inner-blocks-bindingsexperiment. Core backport: WordPress/wordpress-develop#15164.A block bindings source can now supply the inner blocks of a Group or Column block on the front end:
''Other blocks can opt in by adding
innerBlocksthrough theblock_bindings_supported_attributesfilter.Not in this PR: the editor (it still shows the fallback inner blocks), a UI to create the binding, pattern overrides, and automatic excerpts (they need a change in Core's
excerpt_remove_blocks(), which the Core PR has).Why?
A source can fill an attribute, like the text of a paragraph, but not a list of blocks. With this, a template can show things like "the expansions of this game" or "the files attached to this post" as real blocks. It's also the base for free areas in synced patterns.
How?
The code hooks into
block_bindings_source_valueandrender_block. It doesn't changeWP_Block.wp_kses_post(), because it never went through the sanitizing on save. A source whose markup comes from code can turn this off with theblock_bindings_sanitize_inner_blocksfilter. Custom CSS (style.css) is always removed: only users withedit_cssmay add it, and nobody knows who wrote the value. Embeds work as in post content.allowedBlocks,parentorancestor.Testing Instructions
Tests:
npm run test:unit:php:base -- --filter Tests_Block_Bindings_Inner_Blocks.Testing Instructions for Keyboard
No UI changes.
Screenshots or screencast
A test page binds six blocks to a chart source, one for each case the placement handles:
</p>''Cases 3 and 4 are why the placement uses the HTML API. Searching for the last closing tag put the chart inside the paragraph in case 3, and inside the comment in case 4.
Use of AI Tools
I led the design discussion and reviewed the code. Claude Code (Claude Opus) wrote most of the code, the tests and this description. The 54 PHP tests run on wp-env. A local check also rendered every way three source calls can bind each other, with up to two bound Groups per value (6591 renders). It checked that rendering finishes, that nothing stays tracked as rendering, and that the documented blocks render. Look closely at the placement in
gutenberg_block_bindings_get_inner_content_with_slots()and at the source call check ingutenberg_block_bindings_replace_inner_blocks().🤖 Generated with Claude Code