Skip to content

Commit

Permalink
Iframe: always enable for block themes, in core too (#66800)
Browse files Browse the repository at this point in the history
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent f15b4c1 commit b0d2041
Showing 1 changed file with 19 additions and 31 deletions.
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 ) ||
isEditingTemplateOrPattern ||
isZoomOutMode ||
[ 'Tablet', 'Mobile' ].includes( deviceType )
);
}

1 comment on commit b0d2041

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in b0d2041.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11719831461
📝 Reported issues:

Please sign in to comment.