Skip to content

Commit

Permalink
fix inline preview infinite render (#47697)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand authored Feb 6, 2023
1 parent 840ab1f commit 334dc9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
*/
import { BlockPreview } from '@wordpress/block-editor';
import { getBlockType, getBlockFromExample } from '@wordpress/blocks';
import { useResizeObserver } from '@wordpress/compose';
import { __experimentalSpacer as Spacer } from '@wordpress/components';

const BlockPreviewPanel = ( { name, variation = '' } ) => {
const [
containerResizeListener,
{ width: containerWidth, height: containerHeight },
] = useResizeObserver();
const blockExample = getBlockType( name )?.example;
const blockExampleWithVariation = {
...blockExample,
Expand All @@ -25,23 +20,24 @@ const BlockPreviewPanel = ( { name, variation = '' } ) => {
name,
variation ? blockExampleWithVariation : blockExample
);
const viewportWidth = blockExample?.viewportWidth || containerWidth;
const minHeight = containerHeight;
const viewportWidth = blockExample?.viewportWidth || null;
const previewHeight = '150px';

return ! blockExample ? null : (
<Spacer marginX={ 4 } marginBottom={ 4 }>
<div className="edit-site-global-styles__block-preview-panel">
{ containerResizeListener }

<div
className="edit-site-global-styles__block-preview-panel"
style={ { maxHeight: previewHeight, boxSizing: 'initial' } }
>
<BlockPreview
blocks={ blocks }
viewportWidth={ viewportWidth }
minHeight={ minHeight }
minHeight={ previewHeight }
additionalStyles={ [
{
css: `
body{
min-height:${ minHeight }px;
min-height:${ previewHeight };
display:flex;align-items:center;justify-content:center;
}
`,
Expand Down
4 changes: 0 additions & 4 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Variables
$block-preview-height: 150px;

.edit-site-global-styles-preview {
display: flex;
align-items: center;
Expand Down Expand Up @@ -135,7 +132,6 @@ $block-preview-height: 150px;
.edit-site-global-styles__block-preview-panel {
position: relative;
width: 100%;
height: $block-preview-height + 2 * $border-width;
overflow: auto;
border: $gray-200 $border-width solid;
border-radius: $radius-block-ui;
Expand Down

1 comment on commit 334dc9c

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 334dc9c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4106392443
📝 Reported issues:

Please sign in to comment.