From b0d2041e2b1de19aed1f088b4f9b6068cfd89e47 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:06:59 +0100 Subject: [PATCH] Iframe: always enable for block themes, in core too (#66800) Co-authored-by: ellatrix Co-authored-by: jsnajdr --- .../components/layout/use-should-iframe.js | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/packages/edit-post/src/components/layout/use-should-iframe.js b/packages/edit-post/src/components/layout/use-should-iframe.js index 6da344c138f64b..cd2a893d8d1cd0 100644 --- a/packages/edit-post/src/components/layout/use-should-iframe.js +++ b/packages/edit-post/src/components/layout/use-should-iframe.js @@ -11,39 +11,27 @@ import { store as blockEditorStore } from '@wordpress/block-editor'; */ import { unlock } from '../../lock-unlock'; -const isGutenbergPlugin = globalThis.IS_GUTENBERG_PLUGIN ? true : false; - export function useShouldIframe() { - const { - isBlockBasedTheme, - hasV3BlocksOnly, - isEditingTemplateOrPattern, - isZoomOutMode, - deviceType, - } = useSelect( ( select ) => { + return useSelect( ( select ) => { const { getEditorSettings, getCurrentPostType, getDeviceType } = select( editorStore ); - const { isZoomOut } = unlock( select( blockEditorStore ) ); - const { getBlockTypes } = select( blocksStore ); - const editorSettings = getEditorSettings(); - return { - isBlockBasedTheme: editorSettings.__unstableIsBlockBasedTheme, - hasV3BlocksOnly: getBlockTypes().every( ( type ) => { - return type.apiVersion >= 3; - } ), - isEditingTemplateOrPattern: [ 'wp_template', 'wp_block' ].includes( - getCurrentPostType() - ), - isZoomOutMode: isZoomOut(), - deviceType: getDeviceType(), - }; + return ( + // If the theme is block based, we ALWAYS use the iframe for + // consistency across the post and site editor. The iframe was + // introduced long before the sited editor and block themes, so + // these themes are expecting it. + getEditorSettings().__unstableIsBlockBasedTheme || + // For classic themes, we also still want to iframe all the special + // editor features and modes such as device previews, zoom out, and + // template/pattern editing. + getDeviceType() !== 'Desktop' || + [ 'wp_template', 'wp_block' ].includes( getCurrentPostType() ) || + unlock( select( blockEditorStore ) ).isZoomOut() || + // Finally, still iframe the editor for classic themes if all blocks + // are v3 (which means they are marked as iframe-compatible). + select( blocksStore ) + .getBlockTypes() + .every( ( type ) => type.apiVersion >= 3 ) + ); }, [] ); - - return ( - hasV3BlocksOnly || - ( isGutenbergPlugin && isBlockBasedTheme ) || - isEditingTemplateOrPattern || - isZoomOutMode || - [ 'Tablet', 'Mobile' ].includes( deviceType ) - ); }