Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions packages/edit-post/src/components/layout/use-should-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ||

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've essentially only removed isGutenbergPlugin. But I moved all this logic inside the selector to avoid calling all selectors if previous conditions are met.

isEditingTemplateOrPattern ||
isZoomOutMode ||
[ 'Tablet', 'Mobile' ].includes( deviceType )
);
}