-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Description
The latest deprecation migration for a core/group block discards the templateLock set on that block if the value isn't one of the string values but the also valid false.
Step-by-step reproduction instructions
- Start a new post
- Switch to the code editor
- Paste the following:
<!-- wp:group {"templateLock":false} --> <div class="wp-block-group"></div> <!-- /wp:group --> - Click outside the code editor to apply the deprecation migrations and see the
templateLockgets removed instantly turning this into:<!-- wp:group --> <div class="wp-block-group"></div> <!-- /wp:group -->
If you want to see a more real world flow:
- Create a post with a
core/groupblock that doesn't have layout set but atemplateLockvalue offalse.
There are two ways how to do this:- Create the block in an old WP version prior to the default layout, I think 6.0 should already do.
- Manually edit the
post_contentin the database so it looks like this:
<!-- wp:group {"templateLock":false} --> <div class="wp-block-group"></div> <!-- /wp:group --> - Open the post in WP 6.1.
- Switch to Code Editor and see
post_contentnow looks like this:<!-- wp:group --> <div class="wp-block-group"></div> <!-- /wp:group -->
Screenshots, screen recording, code snippet
Video demonstrating the issue:
templateLock.webm
The problem seems to be the deprecation migration to add the default layout, specifically the fact that the templateLock attribute is wrongly defined as string only:
gutenberg/packages/block-library/src/group/deprecated.js
Lines 52 to 54 in b7c693b
| templateLock: { | |
| type: 'string', | |
| }, |
while it can also be bool:
gutenberg/packages/block-library/src/group/block.json
Lines 15 to 18 in b7c693b
| "templateLock": { | |
| "type": [ "string", "boolean" ], | |
| "enum": [ "all", "insert", "contentOnly", false ] | |
| } |
This then leads to the bool attribute being dropped since it is considered invalid but any other string value like all does indeed survive:
templateLock2.webm
This is further proven by the fact that adding this snippet does resolve the issue at hand:
wp.hooks.addFilter(
'blocks.registerBlockType',
'fix/template-lock',
(settings, name) => {
if(
name==='core/group'
&&
settings.deprecated.length === 5
&&
settings.deprecated[0].attributes?.templateLock?.type === 'string'
){
settings.deprecated[0].attributes.templateLock.type = [ "string", "boolean" ];
settings.deprecated[0].attributes.templateLock.enum = [ "all", "insert", "contentOnly", false ];
}
return settings;
}
);
Environment info
- WordPress 6.1.1, without Gutenberg as well as with Gutenberg 15.3.1 enabled
- Firefox
- Desktop with Ubuntu 22.04
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