-
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
Block List: Remove createInnerBlockList utility / context #7192
Conversation
|
||
return { | ||
...prevState, |
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.
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
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 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 😃
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 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 💯
This is a way to extend the BlockMenu in the |
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 had this in mind as well :) Nice refactoring 👍
editor/components/index.js
Outdated
@@ -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'; |
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'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
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.
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.
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.
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.
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.
Let’s merge #7199 in that case 🎉
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' ] ) ), |
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.
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
?
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.
In #7199 @youknowriad proposes how to get rid of
renderBlockMenu
from the context. Would it be possible to pass downuid
toInnerBlocks
instead to avoid exposing it throughBlockEditContext
?
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
?
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 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 :)
9d305d1
to
53b58f0
Compare
53b58f0
to
89087af
Compare
Rebased after the merge of #7199. Now no longer need to expose |
</div> | ||
); | ||
class InnerBlocks extends Component { | ||
componentWillReceiveProps( nextProps ) { |
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.
Can we update this to componentDidUpdate
at the same time?
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.
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.
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.
Nice refactoring
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 theInnerBlocks
component could not depend on components inEditor
.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, arenderBlockMenu
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:
renderBlockMenu
(what's this for again, @youknowriad ?)