diff --git a/src/editor-sidebar/create-panel.js b/src/editor-sidebar/create-panel.js index c6be7d54..5b95d4ff 100644 --- a/src/editor-sidebar/create-panel.js +++ b/src/editor-sidebar/create-panel.js @@ -131,6 +131,7 @@ export const CreateThemePanel = ( { createType } ) => { @@ -163,6 +164,7 @@ export const CreateThemePanel = ( { createType } ) => { /> @@ -175,6 +177,7 @@ export const CreateThemePanel = ( { createType } ) => { /> @@ -187,6 +190,7 @@ export const CreateThemePanel = ( { createType } ) => { /> @@ -199,6 +203,7 @@ export const CreateThemePanel = ( { createType } ) => { /> { { const { createErrorNotice } = useDispatch( noticesStore ); - useSelect( async ( select ) => { - const themeData = select( 'core' ).getCurrentTheme(); - const readmeData = await fetchReadmeData(); + const themeData = useSelect( + ( select ) => select( 'core' ).getCurrentTheme(), + [] + ); + + useEffect( () => { + if ( ! themeData ) { + return; + } + + const fetchData = async () => { + try { + const readmeData = await fetchReadmeData(); + setTheme( { + name: themeData.name.raw, + description: themeData.description.raw, + uri: themeData.theme_uri.raw, + version: themeData.version, + requires_wp: themeData.requires_wp, + author: themeData.author.raw, + author_uri: themeData.author_uri.raw, + tags_custom: themeData.tags.rendered, + screenshot: themeData.screenshot, + recommended_plugins: readmeData.recommended_plugins, + font_credits: readmeData.fonts, + image_credits: readmeData.images, + } ); + } catch ( error ) { + createErrorNotice( + error.message || + __( + 'Failed to fetch theme data.', + 'create-block-theme' + ), + { type: 'snackbar' } + ); + } + }; - setTheme( { - name: themeData.name.raw, - description: themeData.description.raw, - uri: themeData.theme_uri.raw, - version: themeData.version, - requires_wp: themeData.requires_wp, - author: themeData.author.raw, - author_uri: themeData.author_uri.raw, - tags_custom: themeData.tags.rendered, - screenshot: themeData.screenshot, - recommended_plugins: readmeData.recommended_plugins, - font_credits: readmeData.fonts, - image_credits: readmeData.images, - } ); - }, [] ); + fetchData(); + }, [ themeData, createErrorNotice ] ); const handleUpdateClick = () => { postUpdateThemeMetadata( theme ) @@ -152,6 +174,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { { /> @@ -182,6 +206,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { /> @@ -194,6 +219,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { /> @@ -206,6 +232,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { /> @@ -218,6 +245,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { /> { /> { + // TODO: Remove the fallback component when the minimum supported WordPress + // version was increased to 6.7. + const BackButton = Navigator?.BackButton || NavigatorToParentButton; return ( - { { />