Skip to content

Commit 32d5678

Browse files
t-hamanotyxlaciamporamonjd
authored
Fix: Shadow/Font size preset panel crashes the editor (#65765)
* Fix: Shadow/Font size preset panel crashes the editor * Refactor logic Co-authored-by: t-hamano <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: ciampo <[email protected]> Co-authored-by: ramonjd <[email protected]>
1 parent 79e6643 commit 32d5678

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ function FontSize() {
5151
// Get the font size by slug.
5252
const fontSize = sizes.find( ( size ) => size.slug === slug );
5353

54+
// Navigate to the font sizes list if the font size is not available.
55+
useEffect( () => {
56+
if ( ! fontSize ) {
57+
goTo( '/typography/font-sizes/', { isBack: true } );
58+
}
59+
}, [ fontSize, goTo ] );
60+
61+
if ( ! origin || ! slug || ! fontSize ) {
62+
return null;
63+
}
64+
5465
// Whether the font size is fluid. If not defined, use the global fluid value of the theme.
5566
const isFluid =
5667
fontSize?.fluid !== undefined ? !! fontSize.fluid : !! globalFluid;
@@ -121,18 +132,6 @@ function FontSize() {
121132
setIsRenameDialogOpen( ! isRenameDialogOpen );
122133
};
123134

124-
// Navigate to the font sizes list if the font size is not available.
125-
useEffect( () => {
126-
if ( ! fontSize ) {
127-
goTo( '/typography/font-sizes/', { isBack: true } );
128-
}
129-
}, [ fontSize, goTo ] );
130-
131-
// Avoid rendering if the font size is not available.
132-
if ( ! fontSize ) {
133-
return null;
134-
}
135-
136135
return (
137136
<>
138137
<ConfirmDeleteFontSizeDialog

packages/edit-site/src/components/global-styles/shadows-edit-panel.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export default function ShadowsEditPanel() {
9696
const [ isRenameModalVisible, setIsRenameModalVisible ] = useState( false );
9797
const [ shadowName, setShadowName ] = useState( selectedShadow.name );
9898

99+
if ( ! category || ! slug ) {
100+
return null;
101+
}
102+
99103
const onShadowChange = ( shadow ) => {
100104
setSelectedShadow( { ...selectedShadow, shadow } );
101105
const updatedShadows = shadows.map( ( s ) =>

0 commit comments

Comments
 (0)