Skip to content

Commit

Permalink
Performance: Avoid rerendering the sitehub unnecessarily (#55818)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Nov 2, 2023
1 parent a57e08d commit a229cc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
10 changes: 1 addition & 9 deletions packages/edit-site/src/components/layout/index.js
Expand Up @@ -18,7 +18,7 @@ import {
useResizeObserver,
} from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { useState, useRef } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { NavigableRegion } from '@wordpress/interface';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import {
Expand Down Expand Up @@ -72,7 +72,6 @@ export default function Layout() {
useCommonCommands();
useBlockCommands();

const hubRef = useRef();
const { params } = useLocation();
const isMobileViewport = useViewportMatch( 'medium', '<' );
const isListPage = getIsListPage( params, isMobileViewport );
Expand Down Expand Up @@ -226,13 +225,6 @@ export default function Layout() {
animate={ headerAnimationState }
>
<SiteHub
variants={ {
isDistractionFree: { x: '-100%' },
isDistractionFreeHovering: { x: 0 },
view: { x: 0 },
edit: { x: 0 },
} }
ref={ hubRef }
isTransparent={ isResizableFrameOversized }
className="edit-site-layout__hub"
/>
Expand Down
17 changes: 9 additions & 8 deletions packages/edit-site/src/components/site-hub/index.js
Expand Up @@ -18,7 +18,7 @@ import { __ } from '@wordpress/i18n';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { forwardRef } from '@wordpress/element';
import { memo } from '@wordpress/element';
import { search, external } from '@wordpress/icons';
import { store as commandsStore } from '@wordpress/commands';
import { displayShortcut } from '@wordpress/keycodes';
Expand All @@ -32,7 +32,7 @@ import { unlock } from '../../lock-unlock';

const HUB_ANIMATION_DURATION = 0.3;

const SiteHub = forwardRef( ( { isTransparent, ...restProps }, ref ) => {
const SiteHub = memo( ( { isTransparent, className } ) => {
const { canvasMode, dashboardLink, homeUrl, siteTitle } = useSelect(
( select ) => {
const { getCanvasMode, getSettings } = unlock(
Expand Down Expand Up @@ -84,12 +84,13 @@ const SiteHub = forwardRef( ( { isTransparent, ...restProps }, ref ) => {

return (
<motion.div
ref={ ref }
{ ...restProps }
className={ classnames(
'edit-site-site-hub',
restProps.className
) }
className={ classnames( 'edit-site-site-hub', className ) }
variants={ {
isDistractionFree: { x: '-100%' },
isDistractionFreeHovering: { x: 0 },
view: { x: 0 },
edit: { x: 0 },
} }
initial={ false }
transition={ {
type: 'tween',
Expand Down

0 comments on commit a229cc2

Please sign in to comment.