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

Performance: Avoid rerendering the sitehub unnecessarily #55818

Merged
merged 2 commits into from Nov 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is useless.

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={ {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this variants is a prop of SiteHub and not applied directly within the component.

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