Skip to content

Global styles: incorrect usage of Navigator.BackButton #65794

@ciampo

Description

@ciampo

While working on #65790, I noticed that the ScreenHeader has a onBack prop that gets called when Navigator.BackButton gets clicked:

<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

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions