Skip to content

Commit

Permalink
Avoid getTheme call when slug is null (#95570)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsl authored Oct 22, 2024
1 parent 0ba0ed5 commit dee6c50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const usePreviewingTheme = () => {
const previewingThemeSlug = usePreviewingThemeSlug();
const { previewingThemeName } = useSelect(
( select ) => {
// Avoid calling getTheme with null - fetches all site /themes (10s~)
if ( ! previewingThemeSlug ) {
return {
previewingThemeSlug,
previewingThemeName: undefined,
};
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const previewingTheme = ( select( 'core' ) as any ).getTheme( previewingThemeSlug );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { useSelect } from '@wordpress/data';
import domReady from '@wordpress/dom-ready';
import { registerPlugin } from '@wordpress/plugins';
import { usePreviewingThemeSlug } from './hooks/use-previewing-theme';
import LivePreviewNoticePlugin from './live-preview-notice-plugin';

const LivePreviewPlugin = () => {
const siteEditorStore = useSelect( ( select ) => select( 'core/edit-site' ), [] );
const previewingThemeSlug = usePreviewingThemeSlug();

// Do nothing outside the Site Editor context.
if ( ! siteEditorStore ) {
return null;
}

// Don't render unless the user is previewing a theme.
if ( ! previewingThemeSlug ) {
return null;
}

return <LivePreviewNoticePlugin />;
};

Expand Down

0 comments on commit dee6c50

Please sign in to comment.