Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Editor: Try removing extra memoization for individual style panels #57160

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 1 addition & 7 deletions packages/block-editor/src/hooks/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { Platform, useCallback, useRef } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { getFilename } from '@wordpress/url';
import { pure } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -302,7 +301,7 @@ function BackgroundImagePanelItem( { clientId, setAttributes } ) {
);
}

function BackgroundImagePanelPure( props ) {
export function BackgroundImagePanel( props ) {
const [ backgroundImage ] = useSettings( 'background.backgroundImage' );
if (
! backgroundImage ||
Expand All @@ -317,8 +316,3 @@ function BackgroundImagePanelPure( props ) {
</InspectorControls>
);
}

// We don't want block controls to re-render when typing inside a block. `pure`
// will prevent re-renders unless props change, so only pass the needed props
// and not the whole attributes object.
export const BackgroundImagePanel = pure( BackgroundImagePanelPure );
8 changes: 1 addition & 7 deletions packages/block-editor/src/hooks/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import classnames from 'classnames';
*/
import { getBlockSupport } from '@wordpress/blocks';
import { __experimentalHasSplitBorders as hasSplitBorders } from '@wordpress/components';
import { pure } from '@wordpress/compose';
import { Platform, useCallback, useMemo } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';
import { useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -133,7 +132,7 @@ function BordersInspectorControl( { children, resetAllFilter } ) {
);
}

function BorderPanelPure( { clientId, name, setAttributes, settings } ) {
export function BorderPanel( { clientId, name, setAttributes, settings } ) {
const isEnabled = useHasBorderPanel( settings );
function selector( select ) {
const { style, borderColor } =
Expand Down Expand Up @@ -170,11 +169,6 @@ function BorderPanelPure( { clientId, name, setAttributes, settings } ) {
);
}

// We don't want block controls to re-render when typing inside a block. `pure`
// will prevent re-renders unless props change, so only pass the needed props
// and not the whole attributes object.
export const BorderPanel = pure( BorderPanelPure );

/**
* Determine whether there is block support for border properties.
*
Expand Down
8 changes: 1 addition & 7 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import classnames from 'classnames';
import { addFilter } from '@wordpress/hooks';
import { getBlockSupport } from '@wordpress/blocks';
import { useMemo, Platform, useCallback } from '@wordpress/element';
import { pure } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';

/**
Expand Down Expand Up @@ -267,7 +266,7 @@ function ColorInspectorControl( { children, resetAllFilter } ) {
);
}

function ColorEditPure( { clientId, name, setAttributes, settings } ) {
export function ColorEdit( { clientId, name, setAttributes, settings } ) {
const isEnabled = useHasColorPanel( settings );
function selector( select ) {
const { style, textColor, backgroundColor, gradient } =
Expand Down Expand Up @@ -336,11 +335,6 @@ function ColorEditPure( { clientId, name, setAttributes, settings } ) {
);
}

// We don't want block controls to re-render when typing inside a block. `pure`
// will prevent re-renders unless props change, so only pass the needed props
// and not the whole attributes object.
export const ColorEdit = pure( ColorEditPure );

function useBlockProps( {
name,
backgroundColor,
Expand Down
8 changes: 1 addition & 7 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useState, useEffect, useCallback } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { getBlockSupport } from '@wordpress/blocks';
import deprecated from '@wordpress/deprecated';
import { pure } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -66,7 +65,7 @@ function DimensionsInspectorControl( { children, resetAllFilter } ) {
);
}

function DimensionsPanelPure( { clientId, name, setAttributes, settings } ) {
export function DimensionsPanel( { clientId, name, setAttributes, settings } ) {
const isEnabled = useHasDimensionsPanel( settings );
const value = useSelect(
( select ) =>
Expand Down Expand Up @@ -126,11 +125,6 @@ function DimensionsPanelPure( { clientId, name, setAttributes, settings } ) {
);
}

// We don't want block controls to re-render when typing inside a block. `pure`
// will prevent re-renders unless props change, so only pass the needed props
// and not the whole attributes object.
export const DimensionsPanel = pure( DimensionsPanelPure );

/**
* @deprecated
*/
Expand Down
8 changes: 1 addition & 7 deletions packages/block-editor/src/hooks/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
import { useMemo, useCallback } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { pure } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -109,7 +108,7 @@ function TypographyInspectorControl( { children, resetAllFilter } ) {
);
}

function TypographyPanelPure( { clientId, name, setAttributes, settings } ) {
export function TypographyPanel( { clientId, name, setAttributes, settings } ) {
function selector( select ) {
const { style, fontFamily, fontSize } =
select( blockEditorStore ).getBlockAttributes( clientId ) || {};
Expand Down Expand Up @@ -147,11 +146,6 @@ function TypographyPanelPure( { clientId, name, setAttributes, settings } ) {
);
}

// We don't want block controls to re-render when typing inside a block. `pure`
// will prevent re-renders unless props change, so only pass the needed props
// and not the whole attributes object.
export const TypographyPanel = pure( TypographyPanelPure );

export const hasTypographySupport = ( blockName ) => {
return TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) =>
hasBlockSupport( blockName, key )
Expand Down
Loading