Skip to content

Commit

Permalink
Fix being unable to switch modes while inserter is open (#61563)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed May 17, 2024
1 parent 0e9ad3b commit da62eac
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export function useZoomOut( zoomOut = true ) {

return () => {
// We need to use __unstableGetEditorMode() here and not `mode`, as mode may not update on unmount
if ( __unstableGetEditorMode() !== originalEditingMode.current ) {
if (
__unstableGetEditorMode() === 'zoom-out' &&
__unstableGetEditorMode() !== originalEditingMode.current
) {
__unstableSetEditorMode( originalEditingMode.current );
}
};
Expand All @@ -39,7 +42,11 @@ export function useZoomOut( zoomOut = true ) {
useEffect( () => {
if ( zoomOut && mode !== 'zoom-out' ) {
__unstableSetEditorMode( 'zoom-out' );
} else if ( ! zoomOut && originalEditingMode.current !== mode ) {
} else if (
! zoomOut &&
__unstableGetEditorMode() === 'zoom-out' &&
originalEditingMode.current !== mode
) {
__unstableSetEditorMode( originalEditingMode.current );
}
}, [ __unstableSetEditorMode, zoomOut, mode ] );
Expand Down

1 comment on commit da62eac

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in da62eac.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9131032491
📝 Reported issues:

Please sign in to comment.