Fix: properly merged schema during mergeSchemas part in getBlockContentSchemaFromTransforms - #70615
Conversation
|
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 If 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. |
|
@getdave do you think this is ready to be shipped? |
|
Thanks for working on this, I'd love to see this fix land. I believe there's a remaining issue here that's unaddressed. If diff --git c/packages/blocks/src/api/raw-handling/test/utils.js i/packages/blocks/src/api/raw-handling/test/utils.js
index fc532c7400..ae1384dad0 100644
--- c/packages/blocks/src/api/raw-handling/test/utils.js
+++ i/packages/blocks/src/api/raw-handling/test/utils.js
@@ -128,7 +128,9 @@ describe( 'getBlockContentSchema', () => {
children: {
sub: {},
sup: {},
- strong: {},
+ strong: {
+ classes: [ 'test-class' ],
+ },
},
},
},
@@ -146,7 +148,9 @@ describe( 'getBlockContentSchema', () => {
const output = {
pre: {
children: {
- strong: {},
+ strong: {
+ classes: [ 'test-class' ],
+ },
em: {},
sub: {},
sup: {},I discovered this when I tried to capture a target class below the root, but it was always stripped in my transform: -<pre><code class="TARGET_CLASS"></code></pre>
+<pre><code></code></pre>I've confirmed that issue remains on this branch. |
sirreal
left a comment
There was a problem hiding this comment.
A side note: I really miss types when trying to understand all of this logic. We could consider migrating this file to TypeScript as a first step. It could be very beneficial when understanding the recursive data structure.
|
I think this PR is ready for merge now, please let me know if anything else is needed. |
|
This seems ready. @USERSATOSHI will you add a bug fix changelog entry to the package? |
sirreal
left a comment
There was a problem hiding this comment.
Pre-approving. I want to wait for the changelog.
Thanks for this fix!
What?
Closes #70612
This PR fixes the bug where merging schemas causes top level
classesproperty to convert from array to object with indices as keys.Why?
As the classes gets converted to Object the cleanNodeList function fails when it tries to map the classes property.
Error at this line
How?
The Solution checks whether
b[key]is an array or not, if it is an array , seta[key]to be copy of b[key] else the original object shallow clone.Testing Instructions
Follow the instructions of #70612
Screenshots or screencast
Before
Screen.Recording.2025-07-04.at.2.08.59.PM.mov
Results
Screen.Recording.2025-07-04.at.2.35.36.PM.mov
Block Transform Code
Screen.Recording.2025-07-04.at.2.37.14.PM.mov