Skip to content

Commit

Permalink
Block editor: prevent isSubtreeDisabled call if not needed (WordPress…
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Jan 29, 2024
1 parent 0bb25ed commit fcf0b5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 6 additions & 5 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ function BlockListBlockProvider( props ) {
const typing = isTyping();
const hasLightBlockWrapper = blockType?.apiVersion > 1;
const movingClientId = hasBlockMovingClientId();

const blockEditingMode = getBlockEditingMode( clientId );
return {
mode: getBlockMode( clientId ),
isSelectionEnabled: isSelectionEnabled(),
Expand All @@ -574,7 +574,7 @@ function BlockListBlockProvider( props ) {
themeSupportsLayout: supportsLayout,
isTemporarilyEditingAsBlocks:
__unstableGetTemporarilyEditingAsBlocks() === clientId,
blockEditingMode: getBlockEditingMode( clientId ),
blockEditingMode,
mayDisplayControls:
_isSelected ||
( isFirstMultiSelectedBlock( clientId ) &&
Expand All @@ -590,7 +590,9 @@ function BlockListBlockProvider( props ) {
index: getBlockIndex( clientId ),
blockApiVersion: blockType?.apiVersion || 1,
blockTitle: match?.title || blockType?.title,
isSubtreeDisabled: isBlockSubtreeDisabled( clientId ),
isSubtreeDisabled:
blockEditingMode === 'disabled' &&
isBlockSubtreeDisabled( clientId ),
isOutlineEnabled: outlineMode,
hasOverlay: __unstableHasActiveBlockOverlayActive( clientId ),
initialPosition:
Expand All @@ -614,8 +616,7 @@ function BlockListBlockProvider( props ) {
getBlockName( movingClientId ),
getBlockRootClientId( clientId )
),
isEditingDisabled:
getBlockEditingMode( clientId ) === 'disabled',
isEditingDisabled: blockEditingMode === 'disabled',
className: hasLightBlockWrapper
? attributes.className
: undefined,
Expand Down
9 changes: 3 additions & 6 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export function getLastInsertedBlocksClientIds( state ) {
}

/**
* Returns true if the block with the given client ID and all of its descendants
* Returns true if all of the descendants of a block with the given client ID
* have an editing mode of 'disabled', or false otherwise.
*
* @param {Object} state Global application state.
* @param {string} clientId The block client ID.
*
* @return {boolean} Whether the block and its descendants are disabled.
* @return {boolean} Whether the block descendants are disabled.
*/
export const isBlockSubtreeDisabled = createSelector(
( state, clientId ) => {
Expand All @@ -63,10 +63,7 @@ export const isBlockSubtreeDisabled = createSelector(
)
);
};
return (
getBlockEditingMode( state, clientId ) === 'disabled' &&
getBlockOrder( state, clientId ).every( isChildSubtreeDisabled )
);
return getBlockOrder( state, clientId ).every( isChildSubtreeDisabled );
},
( state ) => [
state.blocks.parents,
Expand Down

0 comments on commit fcf0b5d

Please sign in to comment.