Skip to content

Commit 6a09a19

Browse files
committed
Block editor: move layout styles to document head (instead of rendering inline)
1 parent 4060caa commit 6a09a19

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import classnames from 'classnames';
88
*/
99
import { AsyncModeProvider, useSelect } from '@wordpress/data';
1010
import { useViewportMatch, useMergeRefs } from '@wordpress/compose';
11-
import { createContext, useState, useMemo } from '@wordpress/element';
11+
import {
12+
createContext,
13+
useState,
14+
useMemo,
15+
createPortal,
16+
} from '@wordpress/element';
17+
import { createSlotFill } from '@wordpress/components';
1218

1319
/**
1420
* Internal dependencies
@@ -24,8 +30,14 @@ import BlockToolsBackCompat from '../block-tools/back-compat';
2430
import { useBlockSelectionClearer } from '../block-selection-clearer';
2531

2632
export const IntersectionObserver = createContext();
33+
const { Fill: BlockHeadFill, Slot: BlockHeadSlot } = createSlotFill(
34+
'__unstableBlockHead'
35+
);
36+
37+
export { BlockHeadFill };
2738

2839
function Root( { className, children } ) {
40+
const [ element, setElement ] = useState();
2941
const isLargeViewport = useViewportMatch( 'medium' );
3042
const {
3143
isTyping,
@@ -52,6 +64,7 @@ function Root( { className, children } ) {
5264
useBlockSelectionClearer(),
5365
useBlockDropZone(),
5466
useInBetweenInserter(),
67+
setElement,
5568
] ) }
5669
className={ classnames(
5770
'block-editor-block-list__layout is-root-container',
@@ -64,6 +77,8 @@ function Root( { className, children } ) {
6477
}
6578
) }
6679
>
80+
{ element &&
81+
createPortal( <BlockHeadSlot />, element.ownerDocument.head ) }
6782
{ children }
6883
</div>
6984
);

packages/block-editor/src/hooks/layout.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { store as blockEditorStore } from '../store';
2828
import { InspectorControls } from '../components';
2929
import useSetting from '../components/use-setting';
3030
import { LayoutStyle } from '../components/block-list/layout';
31+
import { BlockHeadFill } from '../components/block-list';
3132

3233
function LayoutPanel( { setAttributes, attributes } ) {
3334
const { layout = {} } = attributes;
@@ -209,10 +210,12 @@ export const withLayoutStyles = createHigherOrderComponent(
209210

210211
return (
211212
<>
212-
<LayoutStyle
213-
selector={ `.wp-container-${ id }` }
214-
layout={ usedLayout }
215-
/>
213+
<BlockHeadFill>
214+
<LayoutStyle
215+
selector={ `.wp-container-${ id }` }
216+
layout={ usedLayout }
217+
/>
218+
</BlockHeadFill>
216219
<BlockListBlock { ...props } className={ className } />
217220
</>
218221
);

0 commit comments

Comments
 (0)