Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Nested blocks in a synced pattern are listed multiple times #86

@toshotosho

Description

@toshotosho

Describe the bug
When a nested block structure is put in a synced pattern (reusable block), some of the blocks in the resulting array are listed multiple times.

To Reproduce

  • Create a synced pattern with the following content:
			<!-- wp:group -->
			<div class="wp-block-group">
				<!-- wp:group -->
				<div class="wp-block-group">
					<!-- wp:paragraph -->
					<p>p1</p>
					<!-- /wp:paragraph -->
				</div>
				<!-- /wp:group -->
			</div>
			<!-- /wp:group -->
  • Reference the above pattern into a <!-- wp:block {"ref":%d} /--> in a separate post and check the Block API output.

Expected behavior
I would expect to receive the following (this is PHP from the test I wrote)

[
	[
		'name'        => 'core/block',
		'attributes'  => [
			'ref' => $synced_pattern->ID,
		],
		'innerBlocks' => [
			[
				'name'        => 'core/group',
				'attributes'  => [
					'tagName' => 'div',
				],
				'innerBlocks' => [
					[
						'name'        => 'core/group',
						'attributes'  => [
							'tagName' => 'div',
						],
						'innerBlocks' => [
							[
								'name'       => 'core/paragraph',
								'attributes' => [
									'content' => 'p1',
									'dropCap' => false,
								],
							],
						],
					],
				],
			],
		],
	],
]

Actual behavior
Instead, I'm getting the following:

[
  {
    "name": "core/block",
    "attributes": {
      "ref": 4
    },
    "innerBlocks": [
      {
        "name": "core/paragraph",
        "attributes": {
          "content": "p1",
          "dropCap": false
        }
      },
      {
        "name": "core/group",
        "attributes": {
          "tagName": "div"
        },
        "innerBlocks": [
          {
            "name": "core/paragraph",
            "attributes": {
              "content": "p1",
              "dropCap": false
            }
          }
        ]
      },
      {
        "name": "core/group",
        "attributes": {
          "tagName": "div"
        },
        "innerBlocks": [
          {
            "name": "core/group",
            "attributes": {
              "tagName": "div"
            },
            "innerBlocks": [
              {
                "name": "core/paragraph",
                "attributes": {
                  "content": "p1",
                  "dropCap": false
                }
              }
            ]
          }
        ]
      }
    ]
  }
]

So the core/paragraph block is listed multiple times, in all of its parent blocks. Same for the second core/group. This is different from the output you'd get from the Block API if the blocks in the reusable block structure were used directly and not through a core/block.

Version of the plugin
1.4.3

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions