`supports: {multiple: false}` is inside of a template part, it does not trigger the message that this block is a multiple.
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
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
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.
As far as I remember,
supports.multiple = falseworks 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.
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.
The problem still exists and the steps to reproduce are the same.
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.
This is still an issue and I’m working on a fix.
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.
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:
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
- ❌ 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:
