Skip to content

[BUG] classes property in transforms breaks if it is not defined in the first block schema #70612

@USERSATOSHI

Description

@USERSATOSHI

Description

When an array is provided to classes: property in transforms, during the mergeSchemas part of getBlockContentSchemaFromTransforms, the array gets converted into object.

This only happens when the first rawTranformSchema doesn't have classes property in it.
If the first schema has classes then every other schema's classes stays as array.

Step-by-step reproduction instructions

  1. Create 2 blocks.
  2. Register them.
  3. Add following Transform to the first block
/**
 * WordPress dependencies
 */
import { createBlock } from '@wordpress/blocks';
import metadata from './block.json';

// FIRST CUSTOM BLOCK TO REGISTER

function el(node) {
	return createBlock(metadata.name, {
		content: node.innerHTML,
	});
}

function schema() {
	return {
		ol: {
			classes: ['*'],
			children: '*',
		},
	};
}

const transforms = {
	from: [
		{
			type: 'raw',
			selector: 'ol',
			schema: schema,
			transform: el,
			priority: 9,
		},
	],
};

export default transforms;
  1. Add following transform to the second block.
/**
 * WordPress dependencies
 */
import { createBlock } from '@wordpress/blocks';
import metadata from './block.json';

// SECOND CUSTOM BLOCK TO REGISTER

function el(node) {
	return createBlock(metadata.name, {
		content: node.innerHTML,
	});
}

function schema() {
	return {
		ol: {
			// classes: ['*'],
			children: '*',
		},
	};
}

const transforms = {
	from: [
		{
			type: 'raw',
			selector: 'ol',
			schema: schema,
			transform: el,
			priority: 20,
		},
	],
};

export default transforms;
  1. Open a new post
  2. Paste the following content
<ol class="my-custom-ol list-decimal pl-5 text-gray-800">
  <li class="my-custom-li">First item in the list</li>
  <li class="my-custom-li">Second item in the list</li>
  <li class="my-custom-li">Third item in the list</li>
</ol>

Note: please run npm run start instead of npm run dev, I was not able to reproduce this error on dev but it is consistent on start.

Screenshots, screen recording, code snippet

Screen.Recording.2025-07-04.at.2.08.59.PM.mov

Environment info

  • WordPress: 6.9-alpha-60272
  • PHP: 8.2.28
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 138.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins:
    • Gutenberg Test Plugin, Disable Login Autofocus
    • Gutenberg Test Plugin, Disable Remote Patterns
    • Gutenberg Test Plugin, Enable Templates UI
    • Gutenberg Test Plugin, No-cache Headers
    • Gutenberg Test Plugin, Normalize Theme
    • server-timing.php
  • Plugins:
    • aaaa 0.1.0 -- second custom block
    • Example Static 0.1.0 -- first custom block
    • Gutenberg 21.1.0
    • Test Reports 1.2.0

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

[Feature] Block TransformsBlock transforms from one block to another[Package] Blocks/packages/blocks[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions