-
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
Don't remount the block when the 'templateLock' is set to 'contentOnly' #50292
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -37,7 +33,7 @@ function StopEditingAsBlocksOnOutsideSelect( { | |
if ( ! isBlockOrDescendantSelected ) { | ||
stopEditingAsBlock(); | ||
} | ||
}, [ isBlockOrDescendantSelected ] ); | ||
}, [ isBlockOrDescendantSelected, stopEditingAsBlock ] ); | ||
return null; | ||
} | ||
|
||
|
@@ -91,7 +87,6 @@ export const withBlockControls = createHigherOrderComponent( | |
__unstableSetTemporarilyEditingAsBlocks(); | ||
}, [ | ||
props.clientId, | ||
focusModeToRevert, | ||
updateSettings, | ||
updateBlockListSettings, | ||
getBlockListSettings, | ||
|
@@ -101,7 +96,7 @@ export const withBlockControls = createHigherOrderComponent( | |
] ); | ||
|
||
if ( ! isContentLocked && ! isEditingAsBlocks ) { | ||
return <BlockEdit { ...props } />; | ||
return <BlockEdit key="edit" { ...props } />; | ||
} | ||
|
||
const showStopEditingAsBlocks = isEditingAsBlocks && ! isContentLocked; | ||
|
@@ -156,14 +151,7 @@ export const withBlockControls = createHigherOrderComponent( | |
) } | ||
</BlockSettingsMenuControls> | ||
) } | ||
<BlockEdit | ||
{ ...props } | ||
className={ classnames( | ||
props.className, | ||
isEditingAsBlocks && | ||
'is-content-locked-editing-as-blocks' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is, however, a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. The I double-checked this with the original PR (#43037), and the "edit mode" works as before. |
||
) } | ||
/> | ||
<BlockEdit key="edit" { ...props } /> | ||
</> | ||
); | ||
}, | ||
|
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.
Fixes the ESLin warning. The
stopEditingAsBlock
callback is memoized.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.
The
stopEditingAsBlock
callback has a lot of dependencies, but they are mostlyuseDispatch
return values which should never change. Then there'sclientId
, also constant, and a constantfocusModeToRevert
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 ofuseRef
and is accessed as.current
.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.
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.