Skip to content

Commit

Permalink
Refine approach
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Oct 8, 2024
1 parent 654856d commit eb9a4aa
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,23 @@ export default function ShadowsEditPanel() {
const [ shadows, setShadows ] = useGlobalSetting(
`shadow.presets.${ category }`
);
const currentShadow = shadows?.find( ( shadow ) => shadow.slug === slug );

useEffect( () => {
const currentShadow = shadows?.find(
( shadow ) => shadow.slug === slug
);
// If the shadow being edited doesn't exist anymore in the global styles setting, navigate back
// to prevent the user from editing a non-existent shadow entry.
// This can happen, for example:
// - when the user deletes the shadow
// - when the user resets the styles while editing a custom shadow
if ( ! currentShadow ) {
//
// The check on the slug is necessary to prevent a double back navigation when the user triggers
// a backward navigation by interacting with the screen's UI.
if ( !! slug && ! currentShadow ) {
goBack();
}
}, [ currentShadow, goBack ] );
}, [ shadows, slug, goBack ] );

const [ baseShadows ] = useGlobalSetting(
`shadow.presets.${ category }`,
Expand Down

0 comments on commit eb9a4aa

Please sign in to comment.