-
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
Blocks: Fix BlockEdit hooks not working properly with context #6312
Conversation
@@ -4,7 +4,7 @@ | |||
import { createContext, createHigherOrderComponent } from '@wordpress/element'; | |||
|
|||
const { Consumer, Provider } = createContext( { | |||
isSelected: true, | |||
isSelected: false, |
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.
Should default to false
since we migrated all core blocks to work with the 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.
👌 looks good. I don't see any regressions when clicking through the demo post.
// with which a block is displayed. If `blockType` is valid, assign | ||
// them preferentially as the render value for the block. | ||
const Edit = blockType.edit || blockType.save; | ||
|
||
// For backwards compatibility concerns adds a focus and setFocus prop | ||
// These should be removed after some time (maybe when merging to Core) |
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.
This comment isn't relevant anymore.
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.
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 started #6352 just after merged this one because I realized this when pushing the button :)
All sorted out, thanks for catching 👍
const Component = blockType.edit || blockType.save; | ||
|
||
// For backwards compatibility concerns adds a focus and setFocus prop | ||
// These should be removed after some time (maybe when merging to Core) |
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.
Unrelated, but maybe we should deprecate focus
and setFocus
more formally, e.g. calling deprecated
and removing the functionality in two minor versions.
const componentProps = {
...props,
className,
get focus() {
deprecated( ... );
return isSelected ? {} : false;
},
setFocus() {
deprecated( ... );
},
};
return <Component { ...componentProps } />;
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 guess we didn't include those originally because there was no direct alternative. We did several releases since this change, I think we can just remove it on the next release or so.
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 open a follow-up with those lines removed and scheduled to be included in 2.8 👍
@phpbits, your issue should be now resolved 😃 |
@gziolo Perfect! Waiting for the fixes to be uploaded on the repository :) I'm having issue with building the package locally. |
Description
Addresses the comment shared by @phpbits:
When introducing
BlockEditContext
the handling ofblocks.BlockEdit
hook regressed for the nested blocks. It was caused by the fact that most of the filters wrapBlockEdit
block with additional logic. This made nested blocks to use the parent context which hadisSelected
obviously set tofalse
when editing the child block. I'm not sure why it worked for all other blocks, maybe becauseisSelected
was set totrue
for backward compatibility (I changed tofalse
since we migrated all core blocks). This PR extracts
Editblock to apply filters directly to it and leaves
BlockEdit` block responsible to handle or contexts.How has this been tested?
npm run test
Manual tests. Make sure you can see
Advanced
section for the nested blocks.Types of changes
Bug fix (non-breaking change which fixes an issue).
Checklist: