Blocks: Fix BlockEdit hooks not working properly with context#6312
Blocks: Fix BlockEdit hooks not working properly with context#6312
Conversation
|
|
||
| const { Consumer, Provider } = createContext( { | ||
| isSelected: true, | ||
| isSelected: false, |
There was a problem hiding this comment.
Should default to false since we migrated all core blocks to work with the block edit context.
noisysocks
left a comment
There was a problem hiding this comment.
👌 looks good. I don't see any regressions when clicking through the demo post.
| 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.
This comment isn't relevant anymore.
There was a problem hiding this comment.
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.
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.
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.
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
BlockEditContextthe handling ofblocks.BlockEdithook regressed for the nested blocks. It was caused by the fact that most of the filters wrapBlockEditblock with additional logic. This made nested blocks to use the parent context which hadisSelectedobviously set tofalsewhen editing the child block. I'm not sure why it worked for all other blocks, maybe becauseisSelectedwas set totruefor backward compatibility (I changed tofalsesince we migrated all core blocks). This PR extractsEditblock to apply filters directly to it and leavesBlockEdit` block responsible to handle or contexts.How has this been tested?
npm run testManual tests. Make sure you can see
Advancedsection for the nested blocks.Types of changes
Bug fix (non-breaking change which fixes an issue).
Checklist: