Skip to content

Navigator: fix isInitial, refine focusSelector logic#64786

Merged
ciampo merged 5 commits intotrunkfrom
fix/navigator-provider-logic
Aug 26, 2024
Merged

Navigator: fix isInitial, refine focusSelector logic#64786
ciampo merged 5 commits intotrunkfrom
fix/navigator-provider-logic

Conversation

@ciampo
Copy link
Copy Markdown
Contributor

@ciampo ciampo commented Aug 25, 2024

What?

Part of #59418
Follow-up to #64675

Following the changes applied in #64675, this PR brings fixes and improvements to Navigator's internal logic following @jsnajdr 's comments

Why?

Jarda's comments are all correct and actionable, and would improve the compoment.

How?

Testing Instructions

Both in Storybook and in the editor (Global Styles sidebar):

  • Make sure that isInitial is only applied to the very first location that is assigned when Navigator mounts (currently, on trunk, it gets set to true any time the location's path is the same as the initial path — which is wrong)
  • Make sure that focus restoration continues to work as before (but review the code changes to make sure that the logic is more efficient)

@ciampo ciampo requested a review from jsnajdr August 25, 2024 13:51
@ciampo ciampo self-assigned this Aug 25, 2024
@ciampo ciampo requested a review from a team August 25, 2024 13:52
@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Aug 25, 2024
@ciampo ciampo marked this pull request as ready for review August 25, 2024 13:55
@ciampo ciampo requested a review from ajitbohra as a code owner August 25, 2024 13:55
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 25, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ciampo ciampo changed the title Navigator: fix isInitial & refine focuselector logic Navigator logic: fix isInitial, refine focusSelector Aug 25, 2024
@ciampo ciampo changed the title Navigator logic: fix isInitial, refine focusSelector Navigator: fix isInitial, refine focusSelector logic Aug 25, 2024

### Bug Fixes

- `Navigator`: fix isInitial & refine focus selector logic added in #64675 ([#64786](https://github.com/WordPress/gutenberg/pull/64786)).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There wasn't a release since #64675 was merged, right? Then this changelog entry describes something that a package consumer never had a chance to experience, kind of redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point — I've removed the commit and currently this PR doesn't add any changelog entry.

@@ -82,25 +83,32 @@ function goTo(
return { currentLocation, focusSelectors };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I'm at initial location /foo and call goTo( '/foo' ), it will reset the isInitial flag and that's all. Isn't it going to fire an animation? Like the same UI sliding from right "into itself"?

By the way, all the ?.path optional chainings are not needed, .path is enough.

Copy link
Copy Markdown
Contributor Author

@ciampo ciampo Aug 26, 2024

Choose a reason for hiding this comment

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

If I'm at initial location /foo and call goTo( '/foo' ), it will reset the isInitial flag and that's all. Isn't it going to fire an animation? Like the same UI sliding from right "into itself"?

I don't think "to same screen" navigations have ever been supported — for the animation to work, we'd need to create a clone of the current screen to transition to.

This is true also for "parametrised" screens. For example, if we have a <Navigator.Screen path="/product/:id" />, navigating from /product/1 to product/2 won't currently trigger an animation.

I don't think this has ever been a requirement, and that's why it's not supported.

By the way, all the ?.path optional chainings are not needed, .path is enough.

Good point, I pushed a commit removing those optional chainings

@ciampo ciampo force-pushed the fix/navigator-provider-logic branch from 95da744 to c8a3f44 Compare August 26, 2024 12:08
@ciampo ciampo requested a review from jsnajdr August 26, 2024 12:12
Copy link
Copy Markdown
Member

@jsnajdr jsnajdr left a comment

Choose a reason for hiding this comment

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

:shipit:

@ciampo ciampo merged commit e9a8c6a into trunk Aug 26, 2024
@ciampo ciampo deleted the fix/navigator-provider-logic branch August 26, 2024 13:44
@github-actions github-actions bot added this to the Gutenberg 19.2 milestone Aug 26, 2024
bph pushed a commit to bph/gutenberg that referenced this pull request Aug 31, 2024
* Fix isInitial logic

* Use '@wordpress/warning' instead of console.warn

* Improved destructuring and isInitial assignment

* Refactor focus selector logic, better cleanup, lazier map copy

* Remove unnecessary optional chaining — currentLocation is always defined

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants