-
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
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 |
---|---|---|
|
@@ -29,10 +29,11 @@ export function useShowBlockTools() { | |
const clientId = | ||
getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId(); | ||
|
||
const block = getBlock( clientId ) || { name: '', attributes: {} }; | ||
const block = getBlock( clientId ); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
const isEmptyDefaultBlock = | ||
hasSelectedBlock && isUnmodifiedDefaultBlock( block ); | ||
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. I don't think we should tie the 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. Why even call |
||
const _showEmptyBlockSideInserter = | ||
clientId && | ||
! isTyping() && | ||
|
@@ -43,8 +44,9 @@ export function useShowBlockTools() { | |
! hasMultiSelection() && | ||
editorMode === 'navigation'; | ||
|
||
const isZoomOut = editorMode === 'zoom-out'; | ||
const _showBlockToolbarPopover = | ||
editorMode !== 'zoom-out' && | ||
! isZoomOut && | ||
! getSettings().hasFixedToolbar && | ||
! _showEmptyBlockSideInserter && | ||
hasSelectedBlock && | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Nice find! |
||
isZoomOut && | ||
! _showEmptyBlockSideInserter && | ||
! maybeShowBreadcrumb && | ||
! _showBlockToolbarPopover, | ||
|
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 toisUnmodifiedDefaultBlock
which doesn’t guard against nullish values. Beyond thatblock
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).