Skip to content

Commit

Permalink
Avoid errors when a fontSize preset is not available (WordPress#65791)
Browse files Browse the repository at this point in the history
* Avoid errors when the fontSize is not available

* remove goBack

* Update packages/edit-site/src/components/global-styles/font-sizes/font-size.js

---

Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: firoz2456 <firoz2456@git.wordpress.org>
Co-authored-by: nith53 <nithins53@git.wordpress.org>
Co-authored-by: benniledl <benniledl@git.wordpress.org>
  • Loading branch information
8 people authored Oct 2, 2024
1 parent 3edb570 commit 04d38bc
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +36,6 @@ function FontSize() {

const {
params: { origin, slug },
goBack,
goTo,
} = useNavigator();

Expand All @@ -54,10 +53,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 );
Expand Down Expand Up @@ -107,9 +106,6 @@ function FontSize() {
};

const handleRemoveFontSize = () => {
// Navigate to the font sizes list.
goBack();

const newFontSizes = sizes.filter( ( size ) => size.slug !== slug );
setFontSizes( {
...fontSizes,
Expand All @@ -125,6 +121,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/', { isBack: true } );
}
}, [ fontSize, goTo ] );

// Avoid rendering if the font size is not available.
if ( ! fontSize ) {
return null;
}

return (
<>
<ConfirmDeleteFontSizeDialog
Expand Down

0 comments on commit 04d38bc

Please sign in to comment.