-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Editor: Deprecate layout
attribute
#11029
Conversation
I just wanted to ask for confirmation if it has nothing to do with layout hooks (https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/hooks/layout.js)? |
I wrote a quick layout-based block (sorry, it's ES6 🙈) but it isn't working right. The layouts aren't created in the editor and layout classes are definitely not rendered onto each block, the way they were in the past. I have to guess this is due to changes in However… it's also not working in All the more reason to ditch it! With that said, since /**
* WordPress Dependencies
*/
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { Fragment } from '@wordpress/element';
import { InnerBlocks } from '@wordpress/editor';
/**
* Register block
*/
registerBlockType('tomodomo/layout', {
title: 'Layout Test',
description: 'Test of custom layouts',
keyword: [
'layout',
],
icon: {
background: '#963f69',
foreground: '#FFFFFF',
src: 'columns',
},
category: 'layout',
attributes: {},
edit: (props) => {
return (
<Fragment>
<InnerBlocks
layouts={{
layout1: {
label: 'Layout 1',
icon: 'columns',
},
layout2: {
label: 'Layout 2',
icon: 'columns',
},
}}
/>
</Fragment>
)
},
save: (props) => {
return (
<div>
<InnerBlocks.Content />
</div>
)
},
supports: {
align: [
'wide',
'full',
],
},
}) |
It is related, yes. That entire file would be removed.
This is one of the bigger reasons for removing it. Since it's so rarely used (and completely unused in core) it's all the more likely to be prone to breakage. Not to say that can't be guarded against with tests, but all the hypotheticals around the value of this feature have really not panned out, and it's becoming more of a time sink to support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some notes in a comment, but it seems like layouts
may have actually been broken for some time. All the more reason to ditch, and perhaps ditch without deprecation.
That would be an exception to our normal approach, but in this case I have a hard time imagining anyone is using layouts in a meaningful way (unless they're on a very old version of Gutenberg) considering that they just don't seem to work.
I'm not 100% comfortable commenting on the code in the PR necessarily, but those are my thoughts from a former heavy layouts user :)
EDIT: Somehow missed your reply to my comment @aduth. Sorry! But yes, I agree, let's ditch it.
a2a0cd4
to
6cc32e9
Compare
Since it's a broken API for now, can't we just remove it instead of deprecating it? |
I'm okay with that. I wasn't aware just how non-functional they were. I'll revise this pull request today. |
Rebased and pushed with new approach which removes A few notes:
|
@@ -655,8 +650,7 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { | |||
selectBlock( clientId, initialPosition ); | |||
}, | |||
onInsertBlocks( blocks, index ) { | |||
const { rootClientId, layout } = ownProps; | |||
blocks = blocks.map( ( block ) => cloneBlock( block, { layout } ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cloneBlock
does more than just adding the layout, just want to ensure we don't break anything here. (For example, it clones the inner blocks too etc...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fairly certain this was only used to inject the layout, but I'll double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing which should change is the client ID, which is not something which should be relied upon anyways, and certainly not so for a block which is created but yet to be inserted.
@@ -670,10 +664,6 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { | |||
mergeBlocks( ...args ); | |||
}, | |||
onReplace( blocks ) { | |||
const { layout } = ownProps; | |||
blocks = castArray( blocks ).map( ( block ) => ( | |||
cloneBlock( block, { layout } ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great in my testing.
The Columns migration was indeed broken. It was a bit trickier to restore than I anticipated, since the layout was applied on its inner blocks, not the Columns itself. Should be fixed up in 45cb517, including tests for the migration. |
@@ -0,0 +1,23 @@ | |||
<!-- wp:columns {"columns":3} --> | |||
<div class="wp-block-columns has-3-columns"><!-- wp:column --> | |||
<div class="wp-block-column"><!-- wp:paragraph {"className":"layout-column-1"} --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The className
being kept after the migration may be unexpected, though conversely could better respect backward compatibility. I don't think it's a huge issue to keep, and also would be difficult to omit since the inner blocks are parsed before their parent, so a migration would otherwise need to re-parse and override.
Pouring one out today for layouts. Nice stuff; love the simplification. |
The attributes merging of gutenberg/lib/class-wp-block-type.php Lines 177 to 197 in 45cb517
It still exists today, now in core. |
Related: #7234
Related: #7841
This pull request seeks to deprecate
layout
-related behaviors. As of #7234, no core functionality leverages this feature. Its need has been superseded by the additional functionality of block insertion restrictions viaallowedBlocks
andparent
. It's continued existence has already proven to be a maintenance burden, the removal of which (not done here) will enable a significant simplification to the editor implementation.Testing instructions:
There should be no deprecated warnings when using the editor, since no functionality exists leveraging
layouts
.Verify there are no regressions (nor warnings) in the behavior of drag-and-drop.
Verify that an
InnerBlocks
implementation usinglayouts
still works, but logs warnings (needs example).