-
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
Zoom Out: fix crash due to absence of selected block #63642
Conversation
Size Change: -11 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
Flaky tests detected in 8348800. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9969095471
|
@@ -57,7 +59,8 @@ export function useShowBlockTools() { | |||
! _showEmptyBlockSideInserter && maybeShowBreadcrumb, | |||
showBlockToolbarPopover: _showBlockToolbarPopover, | |||
showZoomOutToolbar: | |||
editorMode === 'zoom-out' && | |||
hasSelectedBlock && |
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.
So this was probably the only key change to fix the issue. The other changes I felt were minor code quality improvements.
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 find!
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
I was going to fix this and found you had already put in a PR. Thanks for the zoom out improvements! I think let's fix just the root issue and maybe add the double bang on hasSelectedBlock
. Otherwise I think we should leave the rest of the hook the same for now.
@@ -29,10 +29,11 @@ export function useShowBlockTools() { | |||
const clientId = | |||
getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId(); | |||
|
|||
const block = getBlock( clientId ) || { name: '', attributes: {} }; | |||
const block = getBlock( clientId ); |
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.
If I recall, we wanted to keep the structure the same if nothing was found due to memoization: { name: '', attributes: {} };
. I think @Mamaduka recommended this.
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.
It seems like the only reason for this is so that block
can be passed to isUnmodifiedDefaultBlock
which doesn’t guard against nullish values. Beyond that block
is unused so it’s okay to be nullish.
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.
Yeah, it's just safe guard - #58979 (comment).
const isEmptyDefaultBlock = isUnmodifiedDefaultBlock( block ); | ||
const hasSelectedBlock = !! clientId && !! block; | ||
const isEmptyDefaultBlock = | ||
hasSelectedBlock && isUnmodifiedDefaultBlock( block ); |
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.
I don't think we should tie the hasSelectedBlock
condition here to the isEmptyDefaultBlock
.
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.
Why even call isUnmodifiedDefaultBlock
if there is no selected block? I.e. without a selection it can’t be a empty default block right?
const editorMode = __unstableGetEditorMode(); | ||
const hasSelectedBlock = clientId && block?.name; | ||
const isEmptyDefaultBlock = isUnmodifiedDefaultBlock( block ); | ||
const hasSelectedBlock = !! clientId && !! block; |
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.
I think the !!
for this line is a good change, but undo the other refactoring.
@@ -57,7 +59,8 @@ export function useShowBlockTools() { | |||
! _showEmptyBlockSideInserter && maybeShowBreadcrumb, | |||
showBlockToolbarPopover: _showBlockToolbarPopover, | |||
showZoomOutToolbar: | |||
editorMode === 'zoom-out' && | |||
hasSelectedBlock && |
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 find!
Thanks for the review 🙇
I know I've made the review less simple so I'm okay with that. Though maybe it’s not too much to ask letting this get a second look before that. |
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.
LGTM. Thanks for the fix.
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 fix tests well for me ✅
Note: I noticed that the undoing pattern insertion is somewhat broken. @jeryj, do you know it's being tracked somewhere?
Screencast
CleanShot.2024-07-19.at.15.34.30.mp4
Thanks to everyone who tested and reviewed. Especially Jerry, whose apt scrutiny of the unnecessary changes made great starting points to explain them. |
What?
A fix for crashes in the editor while zoomed out when either a block is removed or a block is deselected.
Why?
Without this it’s fairly easy to crash the editor in Zoom Out. To fix #63456.
How?
Revises the show block tools hook to avoid returning
true
forshowZoomOutToolbar
when no block is selected.Testing Instructions
Undo while zoomed out
Deselect a block while zoomed out
Testing Instructions for Keyboard
Screenshots or screencast