Skip to content

core/group: add allowedBlocks attribute to latest deprecation#57544

Closed
sque89 wants to merge 1 commit intoWordPress:trunkfrom
sque89:bugfix/group-not-applying-allowed-blocks
Closed

core/group: add allowedBlocks attribute to latest deprecation#57544
sque89 wants to merge 1 commit intoWordPress:trunkfrom
sque89:bugfix/group-not-applying-allowed-blocks

Conversation

@sque89
Copy link
Copy Markdown
Contributor

@sque89 sque89 commented Jan 4, 2024

What?

Fix allowedBlocks attribute of the core/group block

Why?

When adding a block to a post where the template includes a core/group block with the allowedBlocks attribute, the restriction works just fine the same instance and only the allowed blocks are able to be added as a child.

But once a new editor instance is created (reload the editor), the allowedBlocks attribute is completely ignored.

The reason is, that the migrate function of the latest deprecation does not receive the allowedBlocks attribute if it is not defined within its own attributes definition.

How?

I am not not sure if this commit is the correct solution to the problem. It fixes it, but it seems weird to me that i need to add a new attribute to a deprecated version in order to make it persitent during the migration.

Could someone please have a look and tell if that is expected behaviour and therefore the solution to the issue?

Testing Instructions

  1. create a custom block which has a template with a core/group block in it which makes use of the allowedBlocks attribute and which sets the layout attribute of the group like follows: "layout":{"inherit":true}}
  2. add that block to a post and check that only the blockTypes in the allowedBlocks are available
  3. save the post and reload the editor
  4. check again which blockTypes can be added as a child to the group. Now all available blocks are available and the allowedBlocks attribute has no effect anymore

Testing Instructions for Keyboard

Screenshots or screencast

image

@sque89 sque89 requested a review from ajitbohra as a code owner January 4, 2024 12:56
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Block] Group Affects the Group Block (and row, stack and grid variants) labels Jan 4, 2024
@talldan
Copy link
Copy Markdown
Contributor

talldan commented Jan 5, 2024

I personally couldn't reproduce the issue when following the steps. It's working as expected for me.

The addition of allowedBlocks to the group block postdates this particular deprecation, so I wouldn't expect it to need to be added.

@sque89 You may need to narrow down the steps for reproduction. Are you using a clean install of WordPress/Gutenberg when testing or do you have other plugins installed?

@sque89
Copy link
Copy Markdown
Contributor Author

sque89 commented Jan 5, 2024

@talldan thanks a lot for having a look and you are right, i missed a crucial precondition to this issue, sorry. I updated the steps to reproduce and added a screenshot of the relevant part in the code (it is the deprecated.js of the core/group block.

My custom blocks still use the layout inherit option which was apparently deprecated which is the reason why the latest deprecation is eligible for my group blocks.

If that is the case, in the current version, the attributes passed into this deprecation migration do not contain the allowedBlocks attribute, so it gets omitted completely.

Adding the attribute to this deprecation fixes the issue, but as said i am not sure if that is the right way to fix it, or if there is maybe a broader underlaying issue of attribute migration.

@sque89
Copy link
Copy Markdown
Contributor Author

sque89 commented Jan 11, 2024

Any news on this one? It basically breaks my whole enforced layout of our custom blocks because people can start adding anything inside the group which is not desired.

@sque89 sque89 closed this Jan 11, 2024
@sque89 sque89 reopened this Jan 11, 2024
@sque89
Copy link
Copy Markdown
Contributor Author

sque89 commented Feb 12, 2024

@talldan would appreciate if you may could have a look at my answer to your comment. This one is a pretty big problem for us currently. Thanks!

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 12, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @robins@animalequality.de.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: robins@animalequality.de.

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: sque89 <sque@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@talldan
Copy link
Copy Markdown
Contributor

talldan commented Feb 13, 2024

@sque89 Sorry for the delay responding, it's been a busy time.

It would definitely be great to get this issue fixed, though I'm unsure what the right way to fix it is.

My understanding is a deprecation should represent a version of a block almost as a snapshot in time, so if the block didn't have allowedBlocks when the deprecation was created, it shouldn't need it.

I guess what's happening here is that the isElligible method is still causing the deprecation to run even on newer versions of the block 🤔

Deprecations are a generally tricky area—I'll ask for some other input to see if we can help this one across the line.

@tellthemachines
Copy link
Copy Markdown
Contributor

Hello there @sque89,

"layout":{"inherit":true} was deprecated while layout was still an experimental feature, so there's no back compat requirement for it. Even so, back compat has been maintained for it to avoid breakage of existing websites, and that's why it still works for your custom blocks.

The stable equivalent layout is layout: { type: 'constrained' }. If you update your custom blocks to use that format instead of "layout":{"inherit":true}, everything should work as expected.

@sque89
Copy link
Copy Markdown
Contributor Author

sque89 commented Feb 13, 2024

@talldan thanks for getting back on this. But i need to admit that i never looked at it the way @tellthemachines described it. If the feature never left the experimental state and was deprecated in that state, of course this needs to be considered as bad luck. That is exactly the risk when using experimental features.

So after considering that it would be fine for me to ignore this and i will handle the issue myself on our side by updating the blocks.

Thanks to you too for your time, i will close this PR.

@sque89 sque89 closed this Feb 13, 2024
@talldan
Copy link
Copy Markdown
Contributor

talldan commented Feb 14, 2024

Thanks @sque89, glad a solution was found for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Group Affects the Group Block (and row, stack and grid variants) [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants