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

Block List: Remove createInnerBlockList utility / context #7192

Merged
merged 1 commit into from
Jun 20, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Jun 6, 2018

Closes #6943

This pull request seeks to remove the createInnerBlockList utility function and block context property which, as described in #6943, was introduced at a time when the InnerBlocks component could not depend on components in Editor.

This should be a simplification of block context, potentially with some performance and/or memory improvements, as an intermediary component is no longer created and instead the block context contains simpler values: a uid which already existed, a renderBlockMenu function which can hopefully be eliminated at some point. Previously we would create, cache, and pass through a custom component definition for each block, even if that block did not support nesting.

Testing instructions:

Verify there are no regressions to the display an interaction of nested blocks. Of note:

  • Previewing shared nested blocks in the inserter should work as expected
  • renderBlockMenu (what's this for again, @youknowriad ?)

@aduth aduth added [Type] Performance Related to performance efforts [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Code Quality Issues or PRs that relate to code quality labels Jun 6, 2018

return {
...prevState,
Copy link
Member Author

@aduth aduth Jun 6, 2018

Choose a reason for hiding this comment

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

As part of #6419 (ead8dc5), I'm guessing this was previously trying to avoid clobbering the focusedElement and setFocusedElement assigned in constructor. From my testing, this doesn't happen: The return value from getDerivedStateFromProps is applied as patch (same as setState):

Demo: https://codepen.io/aduth/pen/YvGyag

cc @gziolo

Copy link
Member

Choose a reason for hiding this comment

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

I will test it tomorrow. I think it was introduced before and was trying to prevent state updates when props didn’t change by returning null. Maybe your proposal works the same, it would be awesome 😃

Copy link
Member

Choose a reason for hiding this comment

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

I found my commit which I used to test BlockEdit updates: 909844f. Great refactoring, everything works as expected. I didn't discover any regression and the code is much cleaner 💯

@youknowriad
Copy link
Contributor

renderBlockMenu (what's this for again, @youknowriad ?)

This is a way to extend the BlockMenu in the edit-post module. I think we can probably replace it by a Slot. I believe even plugin authors could be interested to hook into this menu. I'll give it a shot in a separate PR.

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 had this in mind as well :) Nice refactoring 👍

@@ -5,6 +5,7 @@ export { default as AlignmentToolbar } from './alignment-toolbar';
export { default as BlockAlignmentToolbar } from './block-alignment-toolbar';
export { default as BlockControls } from './block-controls';
export { default as BlockEdit } from './block-edit';
export { withBlockEditContext } from './block-edit/context';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer if we don't expose this one to avoid confusion with Block edit props for block authors. Hopefully we can get rid of createInnerBlockList

Copy link
Member

Choose a reason for hiding this comment

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

Well, it would allow me to refactor Gallery and Image to remove focus when an image is clicked so I'm not that against exposing it :)

However, I think we agreed that we should avoid exposing this context if possible. If there is a better way to do it, then let's keep this context internal as long as necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we merge #7199, we shouldn't need to export it. It's used exclusively by the shared block in its rendering of <BlockEdit /> which needs renderBlockMenu. If we can make it work with just uid (already passed as a prop to block's edit), then it can be avoided.

Copy link
Member

Choose a reason for hiding this comment

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

Let’s merge #7199 in that case 🎉

@gziolo
Copy link
Member

gziolo commented Jun 7, 2018

I had this in mind as well :) Nice refactoring 👍

Welcome to the club. I tried to keep away myself from it because of the complexity :)

}

InnerBlocks = compose( [
withContext( 'BlockList' )(),
withContext( 'uid' )(),
withBlockEditContext( ( context ) => pick( context, [ 'uid', 'renderBlockMenu' ] ) ),
Copy link
Member

Choose a reason for hiding this comment

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

In #7199 @youknowriad proposes how to get rid of renderBlockMenu from the context. Would it be possible to pass down uid to InnerBlocks instead to avoid exposing it through BlockEditContext?

Copy link
Member Author

Choose a reason for hiding this comment

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

In #7199 @youknowriad proposes how to get rid of renderBlockMenu from the context. Would it be possible to pass down uid to InnerBlocks instead to avoid exposing it through BlockEditContext?

Do you mean pass down as in by the developer in their own rendering of the component? Technically it's possible because we do pass the UID as a prop to edit, but there was a bit of quality-of-life magic meant to be provided by the InnerBlocks. The component also lives inside editor so it doesn't seem like it should be unadvisable to rely on withBlockEditContext ?

Copy link
Member

Choose a reason for hiding this comment

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

The component also lives inside editor so it doesn't seem like it should be unadvisable to rely on withBlockEditContext ?

Right, I saw a file from core-blocks updated and assumed this one belongs there, too. My bad, please skip my comment :)

@aduth aduth force-pushed the remove/create-inner-block-list branch from 9d305d1 to 53b58f0 Compare June 19, 2018 20:51
@aduth aduth force-pushed the remove/create-inner-block-list branch from 53b58f0 to 89087af Compare June 19, 2018 20:54
@aduth
Copy link
Member Author

aduth commented Jun 19, 2018

Rebased after the merge of #7199. Now no longer need to expose withBlockEditContext from the @wordpress/editor module.

</div>
);
class InnerBlocks extends Component {
componentWillReceiveProps( nextProps ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update this to componentDidUpdate at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we update this to componentDidUpdate at the same time?

I went down this path and started to realize there's a fair bit about the behavior of block list settings that needs fixing / improvement. Will make a follow up pull request immediately after this merge.

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.

Nice refactoring

@aduth aduth merged commit 6ba1458 into master Jun 20, 2018
@aduth aduth deleted the remove/create-inner-block-list branch June 20, 2018 18:07
@aduth aduth restored the remove/create-inner-block-list branch June 20, 2018 18:11
@aduth aduth deleted the remove/create-inner-block-list branch June 20, 2018 18:11
@mtias mtias added this to the 3.1 milestone Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Code Quality Issues or PRs that relate to code quality [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants