Skip to content

Fix missing properties in block arrays#10735

Closed
dlh01 wants to merge 3 commits intoWordPress:trunkfrom
dlh01:64505/block-renderer
Closed

Fix missing properties in block arrays#10735
dlh01 wants to merge 3 commits intoWordPress:trunkfrom
dlh01:64505/block-renderer

Conversation

@dlh01
Copy link
Copy Markdown

@dlh01 dlh01 commented Jan 15, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 15, 2026

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dlh, westonruter, mukesh27.

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

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@mukeshpanchal27
Copy link
Copy Markdown
Member

@dlh01
Copy link
Copy Markdown
Author

dlh01 commented Jan 15, 2026

@mukeshpanchal27 Looks like that's an effect of 22294af for https://core.trac.wordpress.org/ticket/64393.

'attrs' => $attributes,
'innerHTML' => '',
'innerContent' => array(),
$block = (array) new WP_Block_Parser_Block(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever way to ensure that any future properties automatically get included. However, if private properties are ever included, then this will result in some unexpected array keys being returned. See https://3v4l.org/JNfY7#veol

So maybe get_object_vars() would be a bit safer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point. While it would be safer, I also observe (and I didn't realize this until right now) that WP_Block_Parser itself also uses the casting approach (example). Better to be consistent here? I don't have a strong preference, just mentioning it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, good catch.

@dlh01
Copy link
Copy Markdown
Author

dlh01 commented Jan 23, 2026

@westonruter As I was doing some other work, I happened to notice that the insert_hooked_blocks() function also contains a malformed block array: it's missing innerHTML. Do you think that'd be worth fixing as part of this ticket or in a new one?

@mukeshpanchal27
Copy link
Copy Markdown
Member

I happened to notice that the insert_hooked_blocks() function also contains a malformed block array: it's missing innerHTML. Do you think that'd be worth fixing as part of this ticket or in a new one?

Why it didn't show any error then?

@dlh01
Copy link
Copy Markdown
Author

dlh01 commented Jan 23, 2026

I happened to notice that the insert_hooked_blocks() function also contains a malformed block array: it's missing innerHTML. Do you think that'd be worth fixing as part of this ticket or in a new one?

Why it didn't show any error then?

It might cause errors, I don't know. I'm not using hooked blocks currently in my own code. This is just an observation from reading the function.

@westonruter
Copy link
Copy Markdown
Member

As I was doing some other work, I happened to notice that the insert_hooked_blocks() function also contains a malformed block array: it's missing innerHTML. Do you think that'd be worth fixing as part of this ticket or in a new one?

Probably best to get @dmsnell's thoughts on this.

@dlh01 dlh01 changed the title Include 'innerBlocks' in simulated block array Fix missing properties in block arrays Jan 26, 2026
Copy link
Copy Markdown
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your understanding and flexibility. I think this is an appropriate tactical change to prevent issues without involving broader questions.

I did end up tossing something together on Friday but didn’t push it out. It does indeed raise some new questions, but I think it does have a role. Just it would be better to get it out on its proper timeline than to rush it for this change.

https://github.com/WordPress/wordpress-develop/pull/10796/files#diff-35597bc06b6f485ad0e5b471c5dc65e15fda8a92bc2debfde2439ae91027f3c9L181-R185

pento pushed a commit that referenced this pull request Mar 17, 2026
There have been a few places in WordPress where a method creates “an array representation simulating the output of parse_blocks”, but the array is missing one or more keys.

The missing keys cause issue with downstream code, which either treats a block without, for example, `innerBlocks` as invalid input, or more commonly, assumes that `innerBlocks` is present and accesses it unconditionally. This can even lead to crashes.

This patch adds the missing properties so that the code behaves as expected. Since the array values are empty by default, adding these missing keys does not present any intentional behavioral changes — only a safer default.

Developed in: #10735
Discussed in: https://core.trac.wordpress.org/ticket/64505

Follow-up to [47360], [57354].

Props dlh, dmsnell, mukesh27, westonruter.
Fixes #64505.


git-svn-id: https://develop.svn.wordpress.org/trunk@62039 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions
Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62039
GitHub commit: 42652a8

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Mar 17, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Mar 17, 2026
There have been a few places in WordPress where a method creates “an array representation simulating the output of parse_blocks”, but the array is missing one or more keys.

The missing keys cause issue with downstream code, which either treats a block without, for example, `innerBlocks` as invalid input, or more commonly, assumes that `innerBlocks` is present and accesses it unconditionally. This can even lead to crashes.

This patch adds the missing properties so that the code behaves as expected. Since the array values are empty by default, adding these missing keys does not present any intentional behavioral changes — only a safer default.

Developed in: WordPress/wordpress-develop#10735
Discussed in: https://core.trac.wordpress.org/ticket/64505

Follow-up to [47360], [57354].

Props dlh, dmsnell, mukesh27, westonruter.
Fixes #64505.

Built from https://develop.svn.wordpress.org/trunk@62039


git-svn-id: http://core.svn.wordpress.org/trunk@61321 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants