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

Editor: Deprecate layout attribute #11029

Merged
merged 4 commits into from
Oct 29, 2018
Merged

Editor: Deprecate layout attribute #11029

merged 4 commits into from
Oct 29, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Oct 24, 2018

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 via allowedBlocks and parent. 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 using layouts still works, but logs warnings (needs example).

@aduth aduth added [Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P labels Oct 24, 2018
@aduth aduth added this to the API Freeze milestone Oct 24, 2018
@gziolo
Copy link
Member

gziolo commented Oct 25, 2018

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)?

@chrisvanpatten
Copy link
Member

chrisvanpatten commented Oct 25, 2018

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 InnerBlocks. It's also possible I made a dumb mistake but I checked in a few places and I am fairly sure my code is correct.

However… it's also not working in master. I would guess this is a regression from a while back that nobody noticed.

All the more reason to ditch it!

With that said, since layouts in their current form are so broken, is it even worth considering just cutting the code without a deprecation?

/**
 * 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',
    ],
  },
})

@aduth
Copy link
Member Author

aduth commented Oct 25, 2018

I just wanted to ask for confirmation if it has nothing to do with layout hooks

It is related, yes. That entire file would be removed.

However… it's also not working in master. I would guess this is a regression from a while back that nobody noticed. All the more reason to ditch it!

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.

Copy link
Member

@chrisvanpatten chrisvanpatten left a 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.

@aduth aduth force-pushed the remove/layout branch 2 times, most recently from a2a0cd4 to 6cc32e9 Compare October 26, 2018 15:04
@youknowriad youknowriad modified the milestones: API Freeze, 4.2 Oct 27, 2018
@youknowriad
Copy link
Contributor

Since it's a broken API for now, can't we just remove it instead of deprecating it?

@aduth
Copy link
Member Author

aduth commented Oct 29, 2018

I'm okay with that. I wasn't aware just how non-functional they were. I'll revise this pull request today.

@aduth
Copy link
Member Author

aduth commented Oct 29, 2018

Rebased and pushed with new approach which removes layout altogether.

A few notes:

  • The simplifications afforded are quite nice, as expected.
  • I want to test (perhaps programmatically) the migration of the old Columns implementation which had used layouts, as with the removal of the hooks, this attribute is no longer added to any block. At worst, we may need to artificially reintroduce the layout attribute for the deprecated column.
  • Technically there are undeprecated breaking changes in e.g. the function signature of the moveBlockToPosition action. It's not expected this would be a very high-use function by third party plugins.
  • We no longer meaningfully use the attributes argument of insertDefaultBlock action, which makes for awkward ergonomics around insertDefaultBlock( undefined, rootClientId, index ). I might suggest we deprecate this first argument, though I have not done so here.
    • For advanced use-cases "initial attributes" could still be supported anyways by insertBlock( createBlock( getDefaultBlockName(), initialAttributes ), rootClientId, index )

@@ -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 } ) );
Copy link
Contributor

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...)

Copy link
Member Author

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.

Copy link
Member Author

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 } )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it ❤️

Copy link
Contributor

@youknowriad youknowriad left a 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.

@aduth
Copy link
Member Author

aduth commented Oct 29, 2018

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"} -->
Copy link
Member Author

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.

@aduth aduth merged commit 8db2764 into master Oct 29, 2018
@aduth aduth deleted the remove/layout branch October 29, 2018 15:18
@chrisvanpatten
Copy link
Member

Pouring one out today for layouts.

Nice stuff; love the simplification.

@aduth
Copy link
Member Author

aduth commented May 26, 2020

The attributes merging of layout should likely have been removed here as well:

/**
* Get all available block attributes including possible layout attribute from Columns block.
*
* @return array Array of attributes.
*/
public function get_attributes() {
return is_array( $this->attributes ) ?
array_merge(
$this->attributes,
array(
'layout' => array(
'type' => 'string',
),
)
) :
array(
'layout' => array(
'type' => 'string',
),
);
}

It still exists today, now in core.

See: https://core.trac.wordpress.org/ticket/50257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants