-
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
Don't remount the block when the 'templateLock' is set to 'contentOnly' #50292
Conversation
className={ classnames( | ||
props.className, | ||
isEditingAsBlocks && | ||
'is-content-locked-editing-as-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.
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 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.
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.
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.
@@ -37,7 +33,7 @@ function StopEditingAsBlocksOnOutsideSelect( { | |||
if ( ! isBlockOrDescendantSelected ) { | |||
stopEditingAsBlock(); | |||
} | |||
}, [ isBlockOrDescendantSelected ] ); | |||
}, [ isBlockOrDescendantSelected, stopEditingAsBlock ] ); |
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 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
.
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.
Size Change: -19 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
@@ -37,7 +33,7 @@ function StopEditingAsBlocksOnOutsideSelect( { | |||
if ( ! isBlockOrDescendantSelected ) { | |||
stopEditingAsBlock(); | |||
} | |||
}, [ isBlockOrDescendantSelected ] ); | |||
}, [ isBlockOrDescendantSelected, stopEditingAsBlock ] ); |
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 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
.
className={ classnames( | ||
props.className, | ||
isEditingAsBlocks && | ||
'is-content-locked-editing-as-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.
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.
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.
Nice cleanup, thanks @Mamaduka 🚀
What?
Fixes #50163.
PR prevents remounting container
BlockEdit
components when thetemplateLock
value iscontentOnly
.Why?
This is similar to #48209.
The
templateLock
and its derived value,isContentLocked
, is initiallyfalse
; after synchronizing the block list settings (updateBlockListSettings
), it becomescontentOnly
. Like the issue above, this causes<BlockEdit />
to be recreated from scratch.How?
Set
key="edit"
on returnedBlockEdit
component from the filter.Testing Instructions
Use the reproduction code from https://gist.github.com/louwie17/20328e1d2c723e34e9cb979dd156fe47, or
templaceLock
attribute tocontentOnly
.edit mounting
.