diff --git a/packages/block-editor/src/components/block-preview/auto.js b/packages/block-editor/src/components/block-preview/auto.js
index 27c147dcd0e72e..db699e36d1d207 100644
--- a/packages/block-editor/src/components/block-preview/auto.js
+++ b/packages/block-editor/src/components/block-preview/auto.js
@@ -4,6 +4,7 @@
import { Disabled } from '@wordpress/components';
import { useResizeObserver, pure, useRefEffect } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
+import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
@@ -16,6 +17,8 @@ import { store } from '../../store';
// This is used to avoid rendering the block list if the sizes change.
let MemoizedBlockList;
+const MAX_HEIGHT = 2000;
+
function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
const [
containerResizeListener,
@@ -33,6 +36,21 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
};
}, [] );
+ // Avoid scrollbars for pattern previews.
+ const editorStyles = useMemo( () => {
+ if ( styles ) {
+ return [
+ ...styles,
+ {
+ css: 'body{height:auto;overflow:hidden;}',
+ __unstableType: 'presets',
+ },
+ ];
+ }
+
+ return styles;
+ }, [ styles ] );
+
// Initialize on render instead of module top level, to avoid circular dependency issues.
MemoizedBlockList = MemoizedBlockList || pure( BlockList );
@@ -46,10 +64,14 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
style={ {
transform: `scale(${ scale })`,
height: contentHeight * scale,
+ maxHeight:
+ contentHeight > MAX_HEIGHT
+ ? MAX_HEIGHT * scale
+ : undefined,
} }
>
}
+ head={ }
assets={ assets }
contentRef={ useRefEffect( ( bodyElement ) => {
const {
@@ -70,6 +92,9 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
width: viewportWidth,
height: contentHeight,
pointerEvents: 'none',
+ // This is a catch-all max-height for patterns.
+ // See: https://github.com/WordPress/gutenberg/pull/38175.
+ maxHeight: MAX_HEIGHT,
} }
>
{ contentResizeListener }