Skip to content

Commit 40a2e8f

Browse files
authored
Block editor: fix performance regression after #57950 (#57971)
1 parent 97e642c commit 40a2e8f

File tree

6 files changed

+24
-33
lines changed

6 files changed

+24
-33
lines changed

packages/block-editor/src/components/block-edit/context.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createContext, useContext } from '@wordpress/element';
55

66
export const mayDisplayControlsKey = Symbol( 'mayDisplayControls' );
77
export const mayDisplayParentControlsKey = Symbol( 'mayDisplayParentControls' );
8+
export const blockEditingModeKey = Symbol( 'blockEditingMode' );
89

910
export const DEFAULT_BLOCK_EDIT_CONTEXT = {
1011
name: '',

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

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
useBlockEditContext,
1414
mayDisplayControlsKey,
1515
mayDisplayParentControlsKey,
16+
blockEditingModeKey,
1617
} from './context';
1718

1819
/**
@@ -28,6 +29,7 @@ export { useBlockEditContext };
2829
export default function BlockEdit( {
2930
mayDisplayControls,
3031
mayDisplayParentControls,
32+
blockEditingMode,
3133
// The remaining props are passed through the BlockEdit filters and are thus
3234
// public API!
3335
...props
@@ -59,6 +61,7 @@ export default function BlockEdit( {
5961
// usage outside of the package (this context is exposed).
6062
[ mayDisplayControlsKey ]: mayDisplayControls,
6163
[ mayDisplayParentControlsKey ]: mayDisplayParentControls,
64+
[ blockEditingModeKey ]: blockEditingMode,
6265
} ),
6366
[
6467
name,
@@ -69,6 +72,7 @@ export default function BlockEdit( {
6972
__unstableLayoutClassNames,
7073
mayDisplayControls,
7174
mayDisplayParentControls,
75+
blockEditingMode,
7276
]
7377
) }
7478
>

packages/block-editor/src/components/block-editing-mode/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* WordPress dependencies
33
*/
44
import { useSelect, useDispatch } from '@wordpress/data';
5-
import { useEffect, useContext } from '@wordpress/element';
5+
import { useEffect } from '@wordpress/element';
66

77
/**
88
* Internal dependencies
99
*/
1010
import { store as blockEditorStore } from '../../store';
11-
import { PrivateBlockContext } from '../block-list/private-block-context';
11+
import {
12+
useBlockEditContext,
13+
blockEditingModeKey,
14+
} from '../block-edit/context';
1215

1316
/**
1417
* @typedef {'disabled'|'contentOnly'|'default'} BlockEditingMode
@@ -45,8 +48,8 @@ import { PrivateBlockContext } from '../block-list/private-block-context';
4548
* @return {BlockEditingMode} The current editing mode.
4649
*/
4750
export function useBlockEditingMode( mode ) {
48-
const { clientId = '', blockEditingMode } =
49-
useContext( PrivateBlockContext );
51+
const context = useBlockEditContext();
52+
const { clientId = '' } = context;
5053
const { setBlockEditingMode, unsetBlockEditingMode } =
5154
useDispatch( blockEditorStore );
5255
const globalBlockEditingMode = useSelect(
@@ -65,5 +68,5 @@ export function useBlockEditingMode( mode ) {
6568
}
6669
};
6770
}, [ clientId, mode, setBlockEditingMode, unsetBlockEditingMode ] );
68-
return clientId ? blockEditingMode : globalBlockEditingMode;
71+
return clientId ? context[ blockEditingModeKey ] : globalBlockEditingMode;
6972
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function BlockListBlock( {
133133
}
134134
mayDisplayControls={ mayDisplayControls }
135135
mayDisplayParentControls={ mayDisplayParentControls }
136+
blockEditingMode={ context.blockEditingMode }
136137
/>
137138
);
138139

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { store as blockEditorStore } from '../../store';
4242
import { useLayout } from './layout';
4343
import useScrollUponInsertion from './use-scroll-upon-insertion';
4444
import { useSettings } from '../use-settings';
45-
import { PrivateBlockContext } from './private-block-context';
4645

4746
const EMPTY_ARRAY = [];
4847

@@ -345,7 +344,7 @@ function BlockListBlock( {
345344
order + 1
346345
);
347346

348-
const block = (
347+
return (
349348
<BlockWrapper
350349
accessibilityLabel={ accessibilityLabel }
351350
blockCategory={ blockCategory }
@@ -397,24 +396,14 @@ function BlockListBlock( {
397396
}
398397
wrapperProps={ wrapperProps }
399398
mayDisplayControls={ mayDisplayControls }
399+
blockEditingMode={ blockEditingMode }
400400
/>
401401
<View onLayout={ onLayout } />
402402
</GlobalStylesContext.Provider>
403403
)
404404
}
405405
</BlockWrapper>
406406
);
407-
408-
return (
409-
<PrivateBlockContext.Provider
410-
value={ {
411-
clientId,
412-
blockEditingMode,
413-
} }
414-
>
415-
{ block }
416-
</PrivateBlockContext.Provider>
417-
);
418407
}
419408

420409
const applyWithSelect = withSelect( ( select, { clientId, rootClientId } ) => {

packages/block-library/src/cover/test/edit.native.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
import { IMAGE_BACKGROUND_TYPE } from '../shared';
3333
import * as paragraph from '../../paragraph';
3434
import * as cover from '..';
35-
import { PrivateBlockContext } from '../../../../block-editor/src/components/block-list/private-block-context';
3635

3736
// Avoid errors due to mocked stylesheet files missing required selectors.
3837
jest.mock( '@wordpress/compose', () => ( {
@@ -81,20 +80,14 @@ const MEDIA_OPTIONS = [
8180
// Simplified tree to render Cover edit within slot.
8281
const CoverEdit = ( props ) => (
8382
<SlotFillProvider>
84-
<PrivateBlockContext.Provider
85-
value={ {
86-
clientId: 0,
87-
} }
88-
>
89-
<BlockEdit
90-
isSelected
91-
mayDisplayControls
92-
name={ cover.name }
93-
clientId={ 0 }
94-
{ ...props }
95-
/>
96-
<BottomSheetSettings isVisible />
97-
</PrivateBlockContext.Provider>
83+
<BlockEdit
84+
isSelected
85+
mayDisplayControls
86+
name={ cover.name }
87+
clientId={ 0 }
88+
{ ...props }
89+
/>
90+
<BottomSheetSettings isVisible />
9891
</SlotFillProvider>
9992
);
10093

0 commit comments

Comments
 (0)