Skip to content

Commit

Permalink
Set outerContainerWidth const
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Oct 16, 2024
1 parent 8aebdfb commit 7091205
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function Iframe( {
}, [] );
const { styles = '', scripts = '' } = resolvedAssets;
const [ iframeDocument, setIframeDocument ] = useState();
const initialContainerWidth = useRef();
const initialContainerWidth = useRef( 0 );
const [ bodyClasses, setBodyClasses ] = useState( [] );
const clearerRef = useBlockSelectionClearer();
const [ before, writingFlowRef, after ] = useWritingFlow();
Expand Down Expand Up @@ -247,6 +247,11 @@ function Iframe( {
}
}, [ containerWidth, isZoomedOut ] );

const outerContainerWidth = Math.max(
initialContainerWidth.current,
containerWidth
);

const disabledRef = useDisabled( { isDisabled: ! readonly } );
const bodyRef = useMergeRefs( [
useBubbleEvents( iframeDocument ),
Expand Down Expand Up @@ -352,10 +357,7 @@ function Iframe( {
scale === 'default'
? ( Math.min( containerWidth, maxWidth ) -
parseInt( frameSize ) * 2 ) /
Math.max(
initialContainerWidth.current,
containerWidth
)
outerContainerWidth
: scale
);

Expand All @@ -378,7 +380,7 @@ function Iframe( {
);
iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-outer-container-width',
`${ Math.max( initialContainerWidth.current, containerWidth ) }px`
`${ outerContainerWidth }px`
);

return () => {
Expand Down Expand Up @@ -410,6 +412,7 @@ function Iframe( {
containerWidth,
windowInnerWidth,
isZoomedOut,
outerContainerWidth,
] );

// Make sure to not render the before and after focusable div elements in view
Expand Down Expand Up @@ -500,11 +503,7 @@ function Iframe( {
) }
style={ {
'--wp-block-editor-iframe-zoom-out-outer-container-width':
isZoomedOut &&
`${ Math.max(
initialContainerWidth.current,
containerWidth
) }px`,
isZoomedOut && `${ outerContainerWidth }px`,
} }
>
{ iframe }
Expand Down

0 comments on commit 7091205

Please sign in to comment.