Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ResizableEditor height based on border-box #66342

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
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
48 changes: 24 additions & 24 deletions packages/editor/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
privateApis as blockEditorPrivateApis,
__experimentalUseResizeCanvas as useResizeCanvas,
} from '@wordpress/block-editor';
import { useEffect, useRef, useMemo } from '@wordpress/element';
import { useEffect, useRef, useMemo, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { parse } from '@wordpress/blocks';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -106,7 +106,10 @@ function VisualEditor( {
contentRef,
className,
} ) {
const [ resizeObserver, sizes ] = useResizeObserver();
const [ contentHeight, setContentHeight ] = useState( '' );
const effectContentHeight = useResizeObserver( ( [ entry ] ) => {
setContentHeight( entry.borderBoxSize[ 0 ].blockSize );
} );
const isMobileViewport = useViewportMatch( 'small', '<' );
const {
renderingMode,
Expand Down Expand Up @@ -323,21 +326,6 @@ function VisualEditor( {
.is-root-container.alignfull { max-width: none; margin-left: auto; margin-right: auto;}
.is-root-container.alignfull:where(.is-layout-flow) > :not(.alignleft):not(.alignright) { max-width: none;}`;

const localRef = useRef();
const typewriterRef = useTypewriter();
contentRef = useMergeRefs( [
localRef,
contentRef,
renderingMode === 'post-only' ? typewriterRef : null,
useFlashEditableBlocks( {
isEnabled: renderingMode === 'template-locked',
} ),
useSelectNearestEditableBlock( {
isEnabled: renderingMode === 'template-locked',
} ),
useZoomOutModeExit(),
] );

Comment on lines -326 to -340
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just moved these down some lines so they’d be after the enableResizing declaration as the arguments to useMergeRefs now depends on it.

const forceFullHeight = postType === NAVIGATION_POST_TYPE;
const enableResizing =
[
Expand Down Expand Up @@ -365,6 +353,24 @@ function VisualEditor( {
];
}, [ styles, enableResizing ] );

const localRef = useRef();
const typewriterRef = useTypewriter();
contentRef = useMergeRefs( [
localRef,
contentRef,
renderingMode === 'post-only' ? typewriterRef : null,
useFlashEditableBlocks( {
isEnabled: renderingMode === 'template-locked',
} ),
useSelectNearestEditableBlock( {
isEnabled: renderingMode === 'template-locked',
} ),
useZoomOutModeExit(),
// Avoid resize listeners when not needed, these will trigger
// unnecessary re-renders when animating the iframe width.
enableResizing ? effectContentHeight : null,
] );

return (
<div
className={ clsx(
Expand All @@ -382,7 +388,7 @@ function VisualEditor( {
<ResizableEditor
enableResizing={ enableResizing }
height={
sizes.height && ! forceFullHeight ? sizes.height : '100%'
contentHeight && ! forceFullHeight ? contentHeight : '100%'
}
>
<BlockCanvas
Expand Down Expand Up @@ -476,12 +482,6 @@ function VisualEditor( {
/>
) }
</RecursionProvider>
{
// Avoid resize listeners when not needed,
// these will trigger unnecessary re-renders
// when animating the iframe width.
enableResizing && resizeObserver
}
</BlockCanvas>
</ResizableEditor>
</div>
Expand Down
Loading