Skip to content
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

Don't remount the block when the 'templateLock' is set to 'contentOnly' #50292

Merged
merged 4 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions packages/block-editor/src/hooks/content-lock-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import { useEffect, useRef, useCallback } from '@wordpress/element';
*/
import { store as blockEditorStore } from '../store';
import { BlockControls, BlockSettingsMenuControls } from '../components';
/**
* External dependencies
*/
import classnames from 'classnames';

function StopEditingAsBlocksOnOutsideSelect( {
clientId,
Expand All @@ -37,7 +33,7 @@ function StopEditingAsBlocksOnOutsideSelect( {
if ( ! isBlockOrDescendantSelected ) {
stopEditingAsBlock();
}
}, [ isBlockOrDescendantSelected ] );
}, [ isBlockOrDescendantSelected, stopEditingAsBlock ] );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the ESLin warning. The stopEditingAsBlock callback is memoized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stopEditingAsBlock callback has a lot of dependencies, but they are mostly useDispatch return values which should never change. Then there's clientId, also constant, and a constant focusModeToRevert ref. I wonder if the ref really needs to be a dependency, in practice it has no effect and I think the ESLint rule will forgive an undeclared dependency that's a return value of useRef and is accessed as .current.

Copy link
Member Author

@Mamaduka Mamaduka May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we have to declare callbacks returned by useDispatch to satisfy the linter, but as you said, they should have a stable reference.

I'll remove focusModeToRevert from dependencies - ca0dd6b.

return null;
}

Expand Down Expand Up @@ -91,7 +87,6 @@ export const withBlockControls = createHigherOrderComponent(
__unstableSetTemporarilyEditingAsBlocks();
}, [
props.clientId,
focusModeToRevert,
updateSettings,
updateBlockListSettings,
getBlockListSettings,
Expand All @@ -101,7 +96,7 @@ export const withBlockControls = createHigherOrderComponent(
] );

if ( ! isContentLocked && ! isEditingAsBlocks ) {
return <BlockEdit { ...props } />;
return <BlockEdit key="edit" { ...props } />;
}

const showStopEditingAsBlocks = isEditingAsBlocks && ! isContentLocked;
Expand Down Expand Up @@ -156,14 +151,7 @@ export const withBlockControls = createHigherOrderComponent(
) }
</BlockSettingsMenuControls>
) }
<BlockEdit
{ ...props }
className={ classnames(
props.className,
isEditingAsBlocks &&
'is-content-locked-editing-as-blocks'
Copy link
Member Author

@Mamaduka Mamaduka May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class isn't used in the editor. Probably a leftover from the original PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is, however, a .is-content-locked-temporarily-editing-as-blocks class that has styles. Can you check whether it maybe should apply to this element? It could be a bug that it's not applied.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. The .is-content-locked-temporarily-editing-as-blocks use used to apply "Spotlight" styling to the block.

I double-checked this with the original PR (#43037), and the "edit mode" works as before.

) }
/>
<BlockEdit key="edit" { ...props } />
</>
);
},
Expand Down