Skip to content

Commit ffc98ab

Browse files
ellatrixMamadukamcsft-hamanostokesman
authored
Post editor: iframe: check inserted rather than registered block versions (#75187)
Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: mcsf <mcsf@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org>
1 parent b706cea commit ffc98ab

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

packages/block-editor/src/components/block-canvas/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function ExperimentalBlockCanvas( {
7070
style={ {
7171
height: '100%',
7272
width: '100%',
73+
overflow: 'auto',
7374
} }
7475
>
7576
{ children }

packages/edit-post/src/components/layout/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function useEditorStyles( settings ) {
134134

135135
/**
136136
* @param {Object} props
137-
* @param {boolean} props.isLegacy True when the editor canvas is not in an iframe.
137+
* @param {boolean} props.isLegacy True for device previews where split view is disabled.
138138
*/
139139
function MetaBoxesMain( { isLegacy } ) {
140140
const [ isOpen, openHeight, hasAnyVisible ] = useSelect( ( select ) => {
@@ -602,11 +602,7 @@ function Layout( {
602602
extraContent={
603603
! isDistractionFree &&
604604
showMetaBoxes && (
605-
<MetaBoxesMain
606-
isLegacy={
607-
! shouldIframe || isDevicePreview
608-
}
609-
/>
605+
<MetaBoxesMain isLegacy={ isDevicePreview } />
610606
)
611607
}
612608
>

packages/edit-post/src/components/layout/style.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@
110110
clear: both;
111111
}
112112

113-
// Only when the split view is active the visual editor should allow shrinking and
114-
// its main size should be zero.
113+
// Only when the split view is active the visual editor should allow shrinking,
114+
// its main size should be zero, and overflow should be hidden so that the inner
115+
// container provides the scrollable viewport.
115116
.has-metaboxes .interface-interface-skeleton__content:has(.edit-post-meta-boxes-main) .editor-visual-editor {
116117
flex-shrink: 1;
117118
flex-basis: 0%;
118-
}
119-
120-
.has-metaboxes .editor-visual-editor.is-iframed {
119+
overflow: hidden;
121120
isolation: isolate;
122121
}
123122

packages/edit-post/src/components/layout/use-should-iframe.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export function useShouldIframe() {
1717
return useSelect( ( select ) => {
1818
const { getEditorSettings, getCurrentPostType, getDeviceType } =
1919
select( editorStore );
20+
const { getClientIdsWithDescendants, getBlockName } =
21+
select( blockEditorStore );
22+
const { getBlockType } = select( blocksStore );
23+
2024
return (
2125
// If the theme is block based and the Gutenberg plugin is active,
2226
// we ALWAYS use the iframe for consistency across the post and site
@@ -29,11 +33,12 @@ export function useShouldIframe() {
2933
getDeviceType() !== 'Desktop' ||
3034
[ 'wp_template', 'wp_block' ].includes( getCurrentPostType() ) ||
3135
unlock( select( blockEditorStore ) ).isZoomOut() ||
32-
// Finally, still iframe the editor if all blocks are v3 (which means
33-
// they are marked as iframe-compatible).
34-
select( blocksStore )
35-
.getBlockTypes()
36-
.every( ( type ) => type.apiVersion >= 3 )
36+
// Finally, still iframe the editor if all present blocks are v3
37+
// (which means they are marked as iframe-compatible).
38+
[ ...new Set( getClientIdsWithDescendants().map( getBlockName ) ) ]
39+
.map( getBlockType )
40+
.filter( Boolean )
41+
.every( ( blockType ) => blockType.apiVersion >= 3 )
3742
);
3843
}, [] );
3944
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5+
6+
test.describe( 'Should iframe', () => {
7+
test.beforeEach( async ( { admin } ) => {
8+
await admin.createNewPost();
9+
} );
10+
11+
test( 'should switch to non-iframe when a v2 block is added', async ( {
12+
page,
13+
editor,
14+
} ) => {
15+
const iframe = page.locator( 'iframe[name="editor-canvas"]' );
16+
17+
// Initially, the editor should be iframed (all core blocks are v3).
18+
await expect( iframe ).toBeVisible();
19+
20+
await page.evaluate( () => {
21+
window.wp.blocks.registerBlockType( 'test/v1', {
22+
apiVersion: 1,
23+
title: 'Test V1 Block',
24+
edit: () =>
25+
window.wp.element.createElement( 'p', null, 'v1 block' ),
26+
save: () => null,
27+
} );
28+
} );
29+
30+
// The editor should still be iframed.
31+
await expect( iframe ).toBeVisible();
32+
33+
// Insert the v1 block.
34+
await editor.insertBlock( { name: 'test/v1' } );
35+
36+
// The editor should no longer be iframed.
37+
await expect( iframe ).toBeHidden();
38+
} );
39+
} );

0 commit comments

Comments
 (0)