-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Refactor the block inspector component to avoid getSelectedBlock #11842
Conversation
|
||
/* | ||
* If the selected block is of an unregistered type, avoid showing it as an actual selection | ||
* because we want the user to focus on the unregistered block warning, not block settings. | ||
*/ | ||
if ( ! selectedBlock || isSelectedBlockUnregistered ) { | ||
if ( ! blockType || ! selectedBlockClientId || isSelectedBlockUnregistered ) { |
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 I don't add blockType
check it fails the e2e test, not sure why.
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.
Things tested well in my smoke tests. The changes seem fine, I left a possible improvement. I would prefer if we had a conclusion on the cause why ! blockType is needed, but the check does not seems ilogical so I dont' think it is a blocker.
@@ -79,15 +78,17 @@ const BlockInspector = ( { selectedBlock, blockType, count, hasBlockStyles } ) = | |||
|
|||
export default withSelect( | |||
( select ) => { | |||
const { getSelectedBlock, getSelectedBlockCount } = select( 'core/editor' ); | |||
const { getSelectedBlockClientId, getSelectedBlockCount, getBlockName } = select( 'core/editor' ); | |||
const { getBlockStyles } = select( 'core/blocks' ); |
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 think we should use getBlockType from select ( 'core/blocks' ); instead of the wp.blocks one, otherwise when there are updates to the blocks our withSelect function may not be executed.
This may be related to the reason end 2 end tests were failing without the blockType check.
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 agree. I think we should avoid relying on getBlockType
(the global) entirely but I didn't want to create inconsistency between components now. This should be done as a dedicated PR at some point.
Extracted from #11811
This PR refactors the block inspector component to use
getSelectedBlockClientId
andgetBlockName
instead ofgetSelectedBlock
which is not very performant.