From 97509d0cc80c289ec1a707fc0d369cac74a5ef54 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 9 Apr 2024 13:26:16 +0100 Subject: [PATCH] Avoid animating global styles NavigatorScreen on initial render --- packages/components/CHANGELOG.md | 1 + .../src/navigator/navigator-provider/component.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 84cd741f5eb749..6f9c5d06709a8b 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -7,6 +7,7 @@ - `ExternalLink`: Use unicode arrow instead of svg icon ([#60255](https://github.com/WordPress/gutenberg/pull/60255)). - `ProgressBar`: Move the indicator width styles from emotion to a CSS variable ([#60388](https://github.com/WordPress/gutenberg/pull/60388)). - `Text`: Add `text-wrap: pretty;` to improve wrapping. ([#60164](https://github.com/WordPress/gutenberg/pull/60164)). +- `Navigator`: Navigation to the active path doesn't create a new location history. ([#60561](https://github.com/WordPress/gutenberg/pull/60561)) ## 27.3.0 (2024-04-03) diff --git a/packages/components/src/navigator/navigator-provider/component.tsx b/packages/components/src/navigator/navigator-provider/component.tsx index c776b036d39b60..368e78d799d72d 100644 --- a/packages/components/src/navigator/navigator-provider/component.tsx +++ b/packages/components/src/navigator/navigator-provider/component.tsx @@ -146,7 +146,6 @@ function routerReducer( action: RouterAction ): RouterState { let { screens, locationHistory, matchedPath } = state; - switch ( action.type ) { case 'add': screens = addScreen( state, action.screen ); @@ -158,6 +157,13 @@ function routerReducer( locationHistory = goBack( state ); break; case 'goto': + if ( + locationHistory.length && + action.path === + locationHistory[ locationHistory.length - 1 ].path + ) { + break; + } locationHistory = goTo( state, action.path, action.options ); break; case 'gotoparent':