Skip to content

Commit

Permalink
Zoom out: fix for inserter (#67495)
Browse files Browse the repository at this point in the history
Makes previousIsZoomedOut a proper ref, and assumes a starting zoom level of 1.
  • Loading branch information
ellatrix authored Dec 2, 2024
1 parent fe8e832 commit 11991fe
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/block-editor/src/components/iframe/use-scale-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* WordPress dependencies
*/
import { useEffect, useRef, useCallback } from '@wordpress/element';
import {
usePrevious,
useReducedMotion,
useResizeObserver,
} from '@wordpress/compose';
import { useReducedMotion, useResizeObserver } from '@wordpress/compose';

/**
* @typedef {Object} TransitionState
Expand Down Expand Up @@ -284,28 +280,35 @@ export function useScaleCanvas( {
transitionFromRef.current = transitionToRef.current;
}, [ iframeDocument ] );

const previousIsZoomedOut = usePrevious( isZoomedOut );
const previousIsZoomedOut = useRef( false );

/**
* Runs when zoom out mode is toggled, and sets the startAnimation flag
* so the animation will start when the next useEffect runs. We _only_
* want to animate when the zoom out mode is toggled, not when the scale
* changes due to the container resizing.
*/
useEffect( () => {
if ( ! iframeDocument || previousIsZoomedOut === isZoomedOut ) {
return;
}
const trigger =
iframeDocument && previousIsZoomedOut.current !== isZoomedOut;

if ( isZoomedOut ) {
iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
previousIsZoomedOut.current = isZoomedOut;

if ( ! trigger ) {
return;
}

startAnimationRef.current = true;

if ( ! isZoomedOut ) {
return;
}

iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
return () => {
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
};
}, [ iframeDocument, isZoomedOut, previousIsZoomedOut ] );
}, [ iframeDocument, isZoomedOut ] );

/**
* This handles:
Expand Down

1 comment on commit 11991fe

@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 11991fe.
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/12125425260
📝 Reported issues:

Please sign in to comment.