Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global styles: incorrect usage of Navigator.BackButton #65794

Open
ciampo opened this issue Oct 1, 2024 · 6 comments
Open

Global styles: incorrect usage of Navigator.BackButton #65794

ciampo opened this issue Oct 1, 2024 · 6 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.

Comments

@ciampo
Copy link
Contributor

ciampo commented Oct 1, 2024

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.

@colorful-tones colorful-tones added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement. labels Oct 1, 2024
@ramonjd
Copy link
Member

ramonjd commented Oct 2, 2024

understand why we need to navigate to / when clicking back.

Thanks for the ping. I think it was because:

  1. There's no intermediate path, so root seemed like the best option
  2. I didn't know about Navigator.BackButton!! TIL

Could we change the code so that Navigator.BackButton's original behaviour is preserved?

I'll test

@ramonjd
Copy link
Member

ramonjd commented Oct 2, 2024

This one is for the global styles: #65810

I looked briefly into the font sizes panel, but it appears there's an existing bug that's preventing testing - the origin and slug are missing from navigation route.

@ramonjd
Copy link
Member

ramonjd commented Oct 2, 2024

I looked briefly into the font sizes panel, but it appears there's an existing bug that's preventing testing - the origin and slug are missing from navigation route.

Fix incoming

@ramonjd
Copy link
Member

ramonjd commented Oct 2, 2024

onBack={ () => goTo( '/typography/font-sizes/' ) }

I think the font sizes component needs this. Otherwise, it'll skip the intermediary font sizes list:

2024-10-02.11.01.17.mp4

So it might need a button refactor as you suggest. I'll just add the fix for the bug I saw for now.

@ciampo
Copy link
Contributor Author

ciampo commented Oct 2, 2024

I looked briefly into the font sizes panel, but it appears there's an existing bug that's preventing testing - the origin and slug are missing from navigation route.

Fix incoming

There are already two PRs with potential fixes:

I admittedly forgot to give y'all context about this bug, my bad

There is also another PR that is fixing a separate issue #65791

Probably better to wait for the dust to settle on these urgent bug fixes, and then look at the code again

@ciampo
Copy link
Contributor Author

ciampo commented Oct 2, 2024

So it might need a button refactor as you suggest. I'll just add the fix for the bug I saw for now.

Could we instead tweak the intermediate screen's path, so that it follows a "hierarchic" URL scheme? That should cause the default behavior of Navigator.BackButton to work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants