gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

`supports: {multiple: false}` is inside of a template part, it does not trigger the message that this block is a multiple.

Open 1337rout opened this issue 3 years ago • 9 comments

Description

I would expect a block that has support: {multiple: false} would still trigger the error if it is added multiple times to a template through the use of template parts or not be allowed within template parts.

Step-by-step reproduction instructions

Add a block that has support: {multiple: false} to a template part. You can now add that block to the template via template parts as many times as you'd like. Easiest way to acomplish this is Create a template part from the block that has support: {multiple: false} and then just duplicate that template part multiple times on the page, notice that the error for a multiple block never triggers. Moving one of the duplicated blocks outside of the template parts triggers the errors. It's just if all of the duplicate blocks are within template parts.

/**
 * WordPress dependencies
 */
import { registerBlockType } from '@wordpress/blocks';

// Register the block
registerBlockType( 'gutenberg-examples/example-01-basic-esnext', {
    edit: function () {
        return <p> Hello world (from the editor)</p>;
    },
    save: function () {
        return <p> Hola mundo (from the frontend) </p>;
    },
   supports: {
       multiple: false
   }
} );

Screenshots, screen recording, code snippet

Screenshot 2023-11-22 at 1 03 50 PM

Environment info

No response

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

1337rout avatar Nov 22 '23 19:11 1337rout

As far as I remember, supports.multiple = false works only in the scope: Template, Template Part, Synced Pattern or Post Content. Template Part block, like other concepts I mentioned, can be modified separately from the rest, so it's nearly impossible to guarantee that when you compose the template with all of them, you will see only one instance of the given block type. In particular, it's getting tricky when you use several copies of the same synced block like Template Part of Synced Pattern where the expectation is that they have identical content. That's said, it's something we should keep discussing as there should be at least a better story told in the documentation so it's clear what to expect.

gziolo avatar Nov 24 '23 09:11 gziolo

As far as I remember, supports.multiple = false works only in the scope: Template, Template Part, Synced Pattern or Post Content. Template Part block, like other concepts I mentioned, can be modified separately from the rest, so it's nearly impossible to guarantee that when you compose the template with all of them, you will see only one instance of the given block type. In particular, it's getting tricky when you use several copies of the same synced block like Template Part of Synced Pattern where the expectation is that they have identical content. That's said, it's something we should keep discussing as there should be at least a better story told in the documentation so it's clear what to expect.

Impossible to do so? I don’t think it’s impossible. When you hit a template part or sync/non-synced patters while looking the results of getBlocks() you need to then get the content of those blocks via clientID to see what all inner blocks are within them. I’m doing something similar for different functionality in a block theme that is yet to be released. If I find the time, I’ll throw up an branch with an example on how to fix.

1337rout avatar Nov 24 '23 14:11 1337rout

Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.

github-actions[bot] avatar Dec 25 '23 00:12 github-actions[bot]

The problem still exists and the steps to reproduce are the same.

1337rout avatar Dec 25 '23 00:12 1337rout

Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.

github-actions[bot] avatar Jan 25 '24 00:01 github-actions[bot]

This is still an issue and I’m working on a fix.

1337rout avatar Jan 25 '24 00:01 1337rout

Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.

github-actions[bot] avatar Feb 25 '24 00:02 github-actions[bot]

Hey @1337rout, I wasn't able to reproduce the issue. The multiple block restriction warning was shown to me as expected when trying to add the block multiple times via template parts. Could you please confirm if the issue still persists on your side?

My environment details:

  • Wordpress: 6.8.2
  • Gutenberg: 21.1.1
  • Theme: Twenty Twenty-Five 1.2

Attaching a screenshot of my result for reference:

Image

BugReportOnWeb avatar Jul 17 '25 16:07 BugReportOnWeb

Reproduction Report

Description

❌ This report can't validate that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 138.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • Greater Than Sign 1.0.0
    • Gutenberg 21.3.0
    • Test Reports 1.2.0

Actual Results

  1. ❌ Error condition is not occurring.

Additional Notes

  • Like @BugReportOnWeb I've testing adding a block with multiple and adding two in the sample template part with identical results.
  • For this reason, it's time to close this ticket as its not possible to replicate. @1337rout comment if you happen to find new reproduction instructions

Supplemental Artifacts

Sample:

SirLouen avatar Jul 31 '25 16:07 SirLouen