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

Fix broken rich text blocks in layout picker preview in Firefox #43822

Merged
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 @@ -9,6 +9,7 @@ import classnames from 'classnames';
*/
/* eslint-disable import/no-extraneous-dependencies */
import {
createPortal,
useRef,
useEffect,
useState,
Expand Down Expand Up @@ -87,7 +88,6 @@ const BlockFramePreview = ( {
title,
} ) => {
const frameContainerRef = useRef();
const renderedBlocksRef = useRef();
const iframeRef = useRef();

// Set the initial scale factor.
Expand Down Expand Up @@ -176,15 +176,6 @@ const BlockFramePreview = ( {
body.scrollTop = 0;
}, [ recomputeBlockListKey ] );

// Append rendered Blocks to iFrame when changed
useEffect( () => {
const renderedBlocksDOM = renderedBlocksRef && renderedBlocksRef.current;

if ( renderedBlocksDOM ) {
iframeRef.current.contentDocument.body.appendChild( renderedBlocksDOM );
}
}, [ recomputeBlockListKey ] );

// Handling windows resize event.
useEffect( () => {
const refreshPreview = debounce( rescale, DEBOUNCE_TIMEOUT );
Expand Down Expand Up @@ -215,22 +206,26 @@ const BlockFramePreview = ( {
title={ __( 'Preview', 'full-site-editing' ) }
className={ classnames( 'editor-styles-wrapper', className ) }
style={ style }
/>

<div ref={ renderedBlocksRef } className="block-editor">
<div className="edit-post-visual-editor">
<div className="editor-styles-wrapper">
<div className="editor-writing-flow">
<CustomBlockPreview
blocks={ renderedBlocks }
settings={ settings }
hidePageTitle={ ! title }
recomputeBlockListKey={ recomputeBlockListKey }
/>
</div>
</div>
</div>
</div>
>
{ iframeRef.current?.contentDocument?.body &&
createPortal(
<div className="block-editor">
<div className="edit-post-visual-editor">
<div className="editor-styles-wrapper">
<div className="editor-writing-flow">
<CustomBlockPreview
blocks={ renderedBlocks }
settings={ settings }
hidePageTitle={ ! title }
recomputeBlockListKey={ recomputeBlockListKey }
/>
</div>
</div>
</div>
</div>,
iframeRef.current.contentDocument.body
) }
</iframe>
</div>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
Expand Down