Skip to content

Commit

Permalink
add condition to set prev container width if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand committed Oct 8, 2024
1 parent 622f41e commit ab13653
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function Iframe( {
const isZoomedOut = scale !== 1;

useEffect( () => {
if ( ! isZoomedOut ) {
if ( ! isZoomedOut || ! prevContainerWidthRef.current ) {
prevContainerWidthRef.current = containerWidth;
}
}, [ containerWidth, isZoomedOut ] );
Expand Down Expand Up @@ -303,8 +303,6 @@ function Iframe( {
return;
}

iframeDocument.documentElement.classList.add( 'is-zoomed-out' );

const maxWidth = 750;
iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-scale',
Expand All @@ -313,6 +311,27 @@ function Iframe( {
prevContainerWidthRef.current
: scale
);

return () => {
iframeDocument.documentElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-scale'
);
};
}, [
scale,
iframeDocument,
isZoomedOut,
containerWidth,
prevContainerWidthRef.current,
] );

useEffect( () => {
if ( ! iframeDocument || ! isZoomedOut ) {
return;
}

iframeDocument.documentElement.classList.add( 'is-zoomed-out' );

iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-frame-size',
typeof frameSize === 'number' ? `${ frameSize }px` : frameSize
Expand All @@ -337,9 +356,6 @@ function Iframe( {
return () => {
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );

iframeDocument.documentElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-scale'
);
iframeDocument.documentElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-frame-size'
);
Expand Down

0 comments on commit ab13653

Please sign in to comment.