Skip to content

Commit

Permalink
Site editor: avoid fetching themes on load (#57985)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Jan 19, 2024
1 parent 7aad6a8 commit 2b82878
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
11 changes: 7 additions & 4 deletions packages/edit-site/src/components/save-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export default function SaveButton( {
const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
const { isSaveViewOpened } = select( editSiteStore );
const isActivatingTheme = isResolving( 'activateTheme' );
const previewingTheme = select( coreStore ).getTheme(
currentlyPreviewingTheme()
);
const currentlyPreviewingThemeId = currentlyPreviewingTheme();

return {
isDirty: dirtyEntityRecords.length > 0,
Expand All @@ -49,7 +47,12 @@ export default function SaveButton( {
)
) || isActivatingTheme,
isSaveViewOpen: isSaveViewOpened(),
previewingThemeName: previewingTheme?.name?.rendered,
// Do not call `getTheme` with null, it will cause a request to
// the server.
previewingThemeName: currentlyPreviewingThemeId
? select( coreStore ).getTheme( currentlyPreviewingThemeId )
?.name?.rendered
: undefined,
};
}, [] );
const { setIsSaveViewOpened } = useDispatch( editSiteStore );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,26 @@ export default function SidebarNavigationScreen( {
description,
backPath: backPathProp,
} ) {
const { dashboardLink, dashboardLinkText } = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
return {
dashboardLink: getSettings().__experimentalDashboardLink,
dashboardLinkText: getSettings().__experimentalDashboardLinkText,
};
}, [] );
const { getTheme } = useSelect( coreStore );
const { dashboardLink, dashboardLinkText, previewingThemeName } = useSelect(
( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
const currentlyPreviewingThemeId = currentlyPreviewingTheme();
return {
dashboardLink: getSettings().__experimentalDashboardLink,
dashboardLinkText:
getSettings().__experimentalDashboardLinkText,
// Do not call `getTheme` with null, it will cause a request to
// the server.
previewingThemeName: currentlyPreviewingThemeId
? select( coreStore ).getTheme( currentlyPreviewingThemeId )
?.name?.rendered
: undefined,
};
},
[]
);
const location = useLocation();
const navigator = useNavigator();
const theme = getTheme( currentlyPreviewingTheme() );
const icon = isRTL() ? chevronRight : chevronLeft;

return (
Expand Down Expand Up @@ -108,7 +117,7 @@ export default function SidebarNavigationScreen( {
? title
: sprintf(
'Previewing %1$s: %2$s',
theme?.name?.rendered,
previewingThemeName,
title
) }
</Heading>
Expand Down

0 comments on commit 2b82878

Please sign in to comment.