diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index 751e940dd166cc..b1d258ffc9ec87 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -217,8 +217,8 @@ function Iframe( { }, [] ); const { - contentResizeListener, - containerResizeListener, + contentRef: scaleContentRef, + containerRef, isZoomedOut, scaleContainerWidth, } = useScaleCanvas( { @@ -234,6 +234,7 @@ function Iframe( { clearerRef, writingFlowRef, disabledRef, + scaleContentRef, ] ); // Correct doctype is required to enable rendering in standards @@ -341,7 +342,6 @@ function Iframe( { ...bodyClasses ) } > - { contentResizeListener } { children } @@ -354,8 +354,7 @@ function Iframe( { ); return ( -
- { containerResizeListener } +
} contentRef A callback ref to the content element. + * @property {import('react').Ref} containerRef A callback ref to the container element. */ /** @@ -157,12 +179,17 @@ export function useScaleCanvas( { maxContainerWidth = 750, scale, } ) { - const [ contentResizeListener, { height: contentHeight } ] = - useResizeObserver(); + const [ { height: contentHeight }, setContentRect ] = useState( NULL_SIZE ); + const contentRef = useResizeObserver( ( entries ) => { + setContentRect( extractSize( entries ) ); + } ); const [ - containerResizeListener, { width: containerWidth, height: containerHeight }, - ] = useResizeObserver(); + setContainerRect, + ] = useState( NULL_SIZE ); + const containerRef = useResizeObserver( ( entries ) => { + setContainerRect( extractSize( entries ) ); + } ); const initialContainerWidthRef = useRef( 0 ); const isZoomedOut = scale !== 1; @@ -484,7 +511,7 @@ export function useScaleCanvas( { return { isZoomedOut, scaleContainerWidth, - contentResizeListener, - containerResizeListener, + contentRef, + containerRef, }; }