Skip to content

Commit

Permalink
Iframe: always enable for block themes, always enable in Gutenberg
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 6, 2024
1 parent fb9587e commit d9234e4
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions packages/edit-post/src/components/layout/use-should-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,33 @@ 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 ) => {
// In the Gutenberg plugin, which acts as a testing ground and is a
// bit more experimental than core, we always use the iframe.
if ( isGutenbergPlugin ) {
return true;
}

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 (
hasV3BlocksOnly ||
( isGutenbergPlugin && isBlockBasedTheme ) ||
isEditingTemplateOrPattern ||
isZoomOutMode ||
[ 'Tablet', 'Mobile' ].includes( deviceType )
);
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 classic editor if all blocks are v3
// (which means they are marked as iframe-compatible).
select( blocksStore )
.getBlockTypes()
.every( ( type ) => type.apiVersion >= 3 )
);
}, [] );
}

0 comments on commit d9234e4

Please sign in to comment.