Skip to content

Commit

Permalink
Block Editor: Animate useScaleCanvas() only when toggling zoomed out …
Browse files Browse the repository at this point in the history
…mode (#67481)

Co-authored-by: tyxla <[email protected]>
Co-authored-by: ellatrix <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent 1d06b35 commit d8a457b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/block-editor/src/components/iframe/use-scale-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* WordPress dependencies
*/
import { useEffect, useRef, useCallback } from '@wordpress/element';
import { useReducedMotion, useResizeObserver } from '@wordpress/compose';
import {
usePrevious,
useReducedMotion,
useResizeObserver,
} from '@wordpress/compose';

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

const previousIsZoomedOut = usePrevious( isZoomedOut );
/**
* 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 ) {
if ( ! iframeDocument || previousIsZoomedOut === isZoomedOut ) {
return;
}

Expand All @@ -300,7 +305,7 @@ export function useScaleCanvas( {
return () => {
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
};
}, [ iframeDocument, isZoomedOut ] );
}, [ iframeDocument, isZoomedOut, previousIsZoomedOut ] );

/**
* This handles:
Expand Down

1 comment on commit d8a457b

@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 d8a457b.
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/12124263016
📝 Reported issues:

Please sign in to comment.