From 29e0fb2eb74d018b8f52233c8f53a6b803ebdecb Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Fri, 23 Aug 2024 18:32:00 +0200 Subject: [PATCH] Set isInitial inside the reducer, instead of on the context value --- .../navigator/navigator-provider/component.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/components/src/navigator/navigator-provider/component.tsx b/packages/components/src/navigator/navigator-provider/component.tsx index b2a72cc3ae2280..8e596778c7f21c 100644 --- a/packages/components/src/navigator/navigator-provider/component.tsx +++ b/packages/components/src/navigator/navigator-provider/component.tsx @@ -39,7 +39,7 @@ type RouterAction = type RouterState = { initialPath: string; screens: Screen[]; - currentLocation?: NavigatorLocation; + currentLocation: NavigatorLocation; matchedPath: MatchedPath; focusSelectors: Map< string, string >; }; @@ -165,6 +165,10 @@ function routerReducer( break; } + if ( currentLocation?.path === state.initialPath ) { + currentLocation = { ...currentLocation, isInitial: true }; + } + // Return early in case there is no change if ( screens === state.screens && @@ -248,19 +252,16 @@ function UnconnectedNavigatorProvider( [] ); - const { currentLocation, matchedPath, initialPath } = routerState; + const { currentLocation, matchedPath } = routerState; const navigatorContextValue: NavigatorContextType = useMemo( () => ( { - location: { - ...currentLocation, - isInitial: currentLocation?.path === initialPath, - }, + location: currentLocation, params: matchedPath?.params ?? {}, match: matchedPath?.id, ...methods, } ), - [ currentLocation, matchedPath, methods, initialPath ] + [ currentLocation, matchedPath, methods ] ); const cx = useCx();