From feecfcf90990cb69b4f80b794adbbee9c7434d01 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Tue, 1 Oct 2024 10:52:40 -0300 Subject: [PATCH 1/3] Avoid errors when the fontSize is not available --- .../global-styles/font-sizes/font-size.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-sizes/font-size.js b/packages/edit-site/src/components/global-styles/font-sizes/font-size.js index 25ff6812d583c9..3afba5f222e08d 100644 --- a/packages/edit-site/src/components/global-styles/font-sizes/font-size.js +++ b/packages/edit-site/src/components/global-styles/font-sizes/font-size.js @@ -15,7 +15,7 @@ import { ToggleControl, } from '@wordpress/components'; import { moreVertical } from '@wordpress/icons'; -import { useState } from '@wordpress/element'; +import { useState, useEffect } from '@wordpress/element'; /** * Internal dependencies @@ -54,10 +54,10 @@ function FontSize() { // Whether the font size is fluid. If not defined, use the global fluid value of the theme. const isFluid = - fontSize.fluid !== undefined ? !! fontSize.fluid : !! globalFluid; + fontSize?.fluid !== undefined ? !! fontSize.fluid : !! globalFluid; // Whether custom fluid values are used. - const isCustomFluid = typeof fontSize.fluid === 'object'; + const isCustomFluid = typeof fontSize?.fluid === 'object'; const handleNameChange = ( value ) => { updateFontSize( 'name', value ); @@ -107,9 +107,6 @@ function FontSize() { }; const handleRemoveFontSize = () => { - // Navigate to the font sizes list. - goBack(); - const newFontSizes = sizes.filter( ( size ) => size.slug !== slug ); setFontSizes( { ...fontSizes, @@ -125,6 +122,18 @@ function FontSize() { setIsRenameDialogOpen( ! isRenameDialogOpen ); }; + // Navigate to the font sizes list if the font size is not available. + useEffect( () => { + if ( ! fontSize ) { + goTo( '/typography/font-sizes/' ); + } + }, [ fontSize, goBack ] ); + + // Avoid rendering if the font size is not available. + if ( ! fontSize ) { + return null; + } + return ( <> Date: Tue, 1 Oct 2024 10:56:35 -0300 Subject: [PATCH 2/3] remove goBack --- .../src/components/global-styles/font-sizes/font-size.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-sizes/font-size.js b/packages/edit-site/src/components/global-styles/font-sizes/font-size.js index 3afba5f222e08d..835cb95f0a7a5e 100644 --- a/packages/edit-site/src/components/global-styles/font-sizes/font-size.js +++ b/packages/edit-site/src/components/global-styles/font-sizes/font-size.js @@ -36,7 +36,6 @@ function FontSize() { const { params: { origin, slug }, - goBack, goTo, } = useNavigator(); @@ -127,7 +126,7 @@ function FontSize() { if ( ! fontSize ) { goTo( '/typography/font-sizes/' ); } - }, [ fontSize, goBack ] ); + }, [ fontSize, goTo ] ); // Avoid rendering if the font size is not available. if ( ! fontSize ) { From 55a7e8b90eb0a5b44b00bb809e906188c86af7b4 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Tue, 1 Oct 2024 22:58:00 -0300 Subject: [PATCH 3/3] Update packages/edit-site/src/components/global-styles/font-sizes/font-size.js Co-authored-by: Marco Ciampini --- .../src/components/global-styles/font-sizes/font-size.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/global-styles/font-sizes/font-size.js b/packages/edit-site/src/components/global-styles/font-sizes/font-size.js index 835cb95f0a7a5e..9970e7354fc382 100644 --- a/packages/edit-site/src/components/global-styles/font-sizes/font-size.js +++ b/packages/edit-site/src/components/global-styles/font-sizes/font-size.js @@ -124,7 +124,7 @@ function FontSize() { // Navigate to the font sizes list if the font size is not available. useEffect( () => { if ( ! fontSize ) { - goTo( '/typography/font-sizes/' ); + goTo( '/typography/font-sizes/', { isBack: true } ); } }, [ fontSize, goTo ] );