Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contentOnly locking and allowedBlocks is not respected in blocks without a layout attribute. #63820

Closed
2 tasks done
ndiego opened this issue Jul 22, 2024 · 4 comments · Fixed by #63837
Closed
2 tasks done
Assignees
Labels
[Feature] Block Locking The API allowing for the ability to lock/unlock blocks [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@ndiego
Copy link
Member

ndiego commented Jul 22, 2024

Description

I just stumbled upon this. If you have a block with "templateLock":"contentOnly" set, the Editor will not respect this attribute if there is no layout attribute as well. This is very bizarre, and it is not clear why the two are tied together. Furthermore, it makes it impossible to create patterns that utilize contentOnly but have no layout constraint.

Edit: I discovered that this issue also occurs when using the allowedBlocks attribute. Unless the block also has a layout attribute, the allowedBlocks restriction will not be implemented.

Step-by-step reproduction instructions

To replicate this issue, copy the following code into the Editor and see that content-only mode is enabled.

Works

<!-- wp:group {"templateLock":"contentOnly","style":{"border":{"radius":"8px","width":"1px"},"spacing":{"blockGap":"0","padding":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20","left":"var:preset|spacing|20","right":"var:preset|spacing|20"}}},"backgroundColor":"white","borderColor":"contrast-3","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-border-color has-contrast-3-border-color has-white-background-color has-background" style="border-width:1px;border-radius:8px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)"><!-- wp:heading {"style":{"typography":{"fontStyle":"normal","fontWeight":"500","fontSize":"1.5rem"}},"fontFamily":"body"} -->
<h2 class="wp-block-heading has-body-font-family" style="font-size:1.5rem;font-style:normal;font-weight:500">Card heading</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"fontSize":"small"} -->
<p class="has-small-font-size">Card description. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

Now copy this code into the Editor and see that the mode no longer works and the "templateLock":"contentOnly" gets stripped out if you toggle on the Layout option "Inner blocks use content width".

Doesn't work

<!-- wp:group {"templateLock":"contentOnly","style":{"border":{"radius":"8px","width":"1px"},"spacing":{"blockGap":"0","padding":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20","left":"var:preset|spacing|20","right":"var:preset|spacing|20"}}},"backgroundColor":"white","borderColor":"contrast-3"} -->
<div class="wp-block-group has-border-color has-contrast-3-border-color has-white-background-color has-background" style="border-width:1px;border-radius:8px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)"><!-- wp:heading {"style":{"typography":{"fontStyle":"normal","fontWeight":"500","fontSize":"1.5rem"}},"fontFamily":"body"} -->
<h2 class="wp-block-heading has-body-font-family" style="font-size:1.5rem;font-style:normal;font-weight:500">Card heading</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"fontSize":"small"} -->
<p class="has-small-font-size">Card description. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

cc @Mamaduka and @jorgefilipecosta as I know you both have worked on block locking and content only.

Screenshots, screen recording, code snippet

With layout set Without layout set
image image

Environment info

  • WordPress 6.6
  • Gutenberg trunk

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
@ndiego ndiego added [Type] Bug An existing feature does not function as intended [Feature] Block Locking The API allowing for the ability to lock/unlock blocks labels Jul 22, 2024
@ndiego ndiego changed the title contentOnly locking is not respected in blocks without a layout attribute. contentOnly locking and allowedBlocks is respected in blocks without a layout attribute. Jul 23, 2024
@ndiego ndiego changed the title contentOnly locking and allowedBlocks is respected in blocks without a layout attribute. contentOnly locking and allowedBlocks is not respected in blocks without a layout attribute. Jul 23, 2024
@talldan
Copy link
Contributor

talldan commented Jul 23, 2024

There was a similar report of this a while back (I'll struggle to find it). I think it was due to the group block being invalid though, and a migration was stripping the allowedBlocks and templateLock attributes.

edit: found it - #57544

@Mamaduka
Copy link
Member

Mamaduka commented Jul 23, 2024

This looks similar to #49159, and it's due to layout deprecation introduced in #42763.

The problem:

  • When the default layout deprecation was introduced. The group block had no support for allowedBlocks and "templateLock" : "contentOnly" attribute values, so they weren't listed when defining deprecation.
  • The deprecation isEligible is true to a missing layout, and these attributes are discarded.

@talldan talldan self-assigned this Jul 23, 2024
@talldan
Copy link
Contributor

talldan commented Jul 23, 2024

So same thing, but in this case the group block is valid. 😬

I have an idea to fix it, but it feels a bit sketchy. I'll put together a PR.

@ndiego
Copy link
Member Author

ndiego commented Jul 23, 2024

Thanks @talldan and @Mamaduka 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Locking The API allowing for the ability to lock/unlock blocks [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants