Skip to content

Commit

Permalink
Set isInitial inside the reducer, instead of on the context value
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Aug 23, 2024
1 parent 7e159f8 commit 29e0fb2
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RouterAction =
type RouterState = {
initialPath: string;
screens: Screen[];
currentLocation?: NavigatorLocation;
currentLocation: NavigatorLocation;
matchedPath: MatchedPath;
focusSelectors: Map< string, string >;
};
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 29e0fb2

Please sign in to comment.