Skip to content

Fix: Propagate block index in recursive processing#1363

Open
ggutenberg wants to merge 1 commit intodevelopfrom
fix/propagate-block-index-in-recursive-processing
Open

Fix: Propagate block index in recursive processing#1363
ggutenberg wants to merge 1 commit intodevelopfrom
fix/propagate-block-index-in-recursive-processing

Conversation

@ggutenberg
Copy link
Contributor

@ggutenberg ggutenberg commented Feb 27, 2026

Description of the Change

When distributing posts that contain registered data (e.g., media IDs registered via distributor_register_data) inside inner blocks — such as core/image blocks nested inside core/columns — all sibling inner block instances incorrectly receive extra_data from index 0 instead of their own sequential index. In practice this means every image in a columns layout is replaced with the media item from the first column, overwriting the correct media for subsequent columns.

Root cause: In RegisteredDataHandler::process_blocks_data_recursive(), the $index counter is passed by value into each recursive call for inner blocks, but the updated value returned by that call is never read back. Once the recursive call returns, $index still holds its pre-call value, so the next parallel branch of inner blocks starts counting from the wrong position.

Fix: Three minimal changes to process_blocks_data_recursive():

  1. PHPDoc @return tag — document that the returned array always includes an 'index' key.
  2. Early-return path — add 'index' => $index to the early-return array so every code path returns a consistent shape.
  3. After recursive call — propagate the child counter back to the parent with $index = $inner_result['index'], ensuring sibling branches receive the correct offset.

How to test the Change

  1. On a multisite or two-site Distributor setup, register a media data handler using distributor_register_data targeting core/image blocks (the built-in dt_post_distribute_media_cb callback works).
  2. Create a post on the source site containing a core/columns block with at least two columns, placing a different image block in each column.
  3. Distribute (push or pull) that post to a destination site.
  4. On the destination site, open the distributed post and confirm that each column contains the correct, distinct image — not a duplicate of the first column's image.
  5. Verify the same behaviour with three or more columns to confirm the index increments correctly across all siblings.
  6. Run the PHP unit test suite (composer run-tests) and confirm all tests pass.

Changelog Entry

Fixed - Ensure the block index is correctly propagated during recursive processing of registered data, so inner blocks (e.g., images inside columns) receive the right extra_data on distribution.

Credits

Props @ggutenberg

Checklist:

…orrectly track block instance order across inner blocks
@github-actions github-actions bot added this to the 2.3.0 milestone Feb 27, 2026
@ggutenberg ggutenberg marked this pull request as ready for review February 27, 2026 14:36
@ggutenberg ggutenberg requested a review from a team as a code owner February 27, 2026 14:36
@ggutenberg ggutenberg requested review from peterwilsoncc and removed request for a team February 27, 2026 14:36
@github-actions github-actions bot added the needs:code-review This requires code review. label Feb 27, 2026
@jeffpaul jeffpaul moved this to Code Review in Open Source Practice Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

Status: Code Review

Development

Successfully merging this pull request may close these issues.

3 participants