Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,16 @@ export function useScaleCanvas( {
* changes due to the container resizing.
*/
useEffect( () => {
const trigger =
iframeDocument && previousIsZoomedOut.current !== isZoomedOut;
// If we don't have an iframe document, we don't run or track the animation.
if ( ! iframeDocument ) {
return;
}

const triggerAnimation = isZoomedOut !== previousIsZoomedOut.current;
previousIsZoomedOut.current = isZoomedOut;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is testing well for me. I think I'd prefer to keep the previous previousIsZoomedOut.current !== isZoomedOut alongside the setting of the ref though. I think it will be easier to understand why we don't want the animation to run when the iframeDocument is false. What do you think of this instead?

// If we don't have an iframe document, we don't run or track the animation.
if ( ! iframeDocument ) {
	return;
}

const triggerAnimation = isZoomedOut !== previousIsZoomedOut.current;
previousIsZoomedOut.current = isZoomedOut;

// Zoom state has not changed, so we don't need to run the animation.
if ( ! triggerAnimation ) {
	return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 0dbaf38

The suggested logic seems to work correctly!


if ( ! trigger ) {
// Zoom state has not changed, so we don't need to run the animation.
if ( ! triggerAnimation ) {
return;
}

Expand Down
Loading