Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use goBack instead of goTo, add extra slug check to avoid double goBa…
…ck call
  • Loading branch information
ciampo committed Oct 8, 2024
commit 28ce4031a769da2d2223f059f14833ee11656279
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function FontSize() {

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

const [ fontSizes, setFontSizes ] = useGlobalSetting(
Expand All @@ -53,10 +53,10 @@ function FontSize() {

// Navigate to the font sizes list if the font size is not available.
useEffect( () => {
if ( ! fontSize ) {
goTo( '/typography/font-sizes/', { isBack: true } );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using goTo here was hiding a bug, where goTo was being called twice. The fix is to also check for the slug, which then makes the code only run once

if ( !! slug && ! fontSize ) {
goBack();
}
}, [ fontSize, goTo ] );
}, [ slug, fontSize, goBack ] );

if ( ! origin || ! slug || ! fontSize ) {
return null;
Expand Down