Don't remount the block when the 'templateLock' is set to 'contentOnly'#50292
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.
This class isn't used in the editor. Probably a leftover from the original PR.
There was a problem hiding this comment.
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.
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.
| stopEditingAsBlock(); | ||
| } | ||
| }, [ isBlockOrDescendantSelected ] ); | ||
| }, [ isBlockOrDescendantSelected, stopEditingAsBlock ] ); |
There was a problem hiding this comment.
Fixes the ESLin warning. The stopEditingAsBlock callback is memoized.
There was a problem hiding this comment.
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.
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
|
| stopEditingAsBlock(); | ||
| } | ||
| }, [ isBlockOrDescendantSelected ] ); | ||
| }, [ isBlockOrDescendantSelected, stopEditingAsBlock ] ); |
There was a problem hiding this comment.
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.
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.
What?
Fixes #50163.
PR prevents remounting container
BlockEditcomponents when thetemplateLockvalue iscontentOnly.Why?
This is similar to #48209.
The
templateLockand 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 returnedBlockEditcomponent from the filter.Testing Instructions
Use the reproduction code from https://gist.github.com/louwie17/20328e1d2c723e34e9cb979dd156fe47, or
templaceLockattribute tocontentOnly.edit mounting.