-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
While working on #65790, I noticed that the ScreenHeader has a onBack prop that gets called when Navigator.BackButton gets clicked:
gutenberg/packages/edit-site/src/components/global-styles/header.js
Lines 21 to 26 in 8e4aac8
| <Navigator.BackButton | |
| icon={ isRTL() ? chevronRight : chevronLeft } | |
| size="small" | |
| label={ __( 'Back' ) } | |
| onClick={ onBack } | |
| /> |
Navigator.BackButton already performs a backward navigation (to the "parent" screen) — but I noticed usages where consumers of ScreenHeader use the onBack callback to trigger another navigation. This can cause unintended consequences, since it may trigger Navigator to make two consecutive navigations.
I could spot two usages:
Font sizes screen
gutenberg/packages/edit-site/src/components/global-styles/font-sizes/font-size.js
Line 154 in 8e4aac8
| onBack={ () => goTo( '/typography/font-sizes/' ) } |
Calling goTo seems totally unnecessary here — if we just let Navigator.BackButton do its job, I believe it would take us to the same screen. Also, using goTo without the isBack option causes the transition to move in the wrong direction.
Revisions screen
gutenberg/packages/edit-site/src/components/global-styles/screen-revisions/index.js
Line 143 in 8e4aac8
| onBack={ onCloseRevisions } |
Here I may need @ramonjd and @andrewserong 's help to understand why we need to navigate to / when clicking back.
Could we change the code so that Navigator.BackButton's original behaviour is preserved?
Alternatively, we'll need to see if we can preventDefault, or consider rendering a Button (instead of Navigator.BackButton) in ScreenHeader, and make the onBack callback an alternative to the "default" going back behaviour, instead of an addition.