diff --git a/packages/block-library/src/html/edit.js b/packages/block-library/src/html/edit.js
index 5c57d73ae40f6..9a1972d54b7e6 100644
--- a/packages/block-library/src/html/edit.js
+++ b/packages/block-library/src/html/edit.js
@@ -7,6 +7,7 @@ import {
BlockControls,
PlainText,
useBlockProps,
+ store as blockEditorStore,
} from '@wordpress/block-editor';
import {
ToolbarButton,
@@ -14,6 +15,7 @@ import {
ToolbarGroup,
VisuallyHidden,
} from '@wordpress/components';
+import { useSelect } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
/**
@@ -27,6 +29,10 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) {
const instanceId = useInstanceId( HTMLEdit, 'html-edit-desc' );
+ const isPreviewMode = useSelect( ( select ) => {
+ return select( blockEditorStore ).getSettings().isPreviewMode;
+ }, [] );
+
function switchToPreview() {
setIsPreview( true );
}
@@ -58,7 +64,7 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) {
- { isPreview || isDisabled ? (
+ { isPreview || isPreviewMode || isDisabled ? (
<>
select( blockEditorStore ).getSettings().styles
+ ( select ) => select( blockEditorStore ).getSettings().styles,
+ []
);
const styles = useMemo(
() => [
DEFAULT_STYLES,
...transformStyles(
- settingStyles.filter( ( style ) => style.css )
+ ( settingStyles ?? [] ).filter( ( style ) => style.css )
),
],
[ settingStyles ]