Skip to content

Commit

Permalink
getPathFromState cache normalized configs calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-mikolajczak committed Aug 29, 2024
1 parent ff948e1 commit 2ef46bd
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/node_modules/@react-navigation/core/src/getPathFromState.tsx b/node_modules/@react-navigation/core/src/getPathFromState.tsx
index 26a6213..2d8f51e 100644
--- a/node_modules/@react-navigation/core/src/getPathFromState.tsx
+++ b/node_modules/@react-navigation/core/src/getPathFromState.tsx
@@ -37,6 +37,8 @@ const getActiveRoute = (state: State): { name: string; params?: object } => {
return route;
};

+let cachedNormalizedConfigsRef: [PathConfigMap<{}> | undefined, Record<string, ConfigItem>] = [undefined, {}];
+
/**
* Utility to serialize a navigation state object to a path string.
*
@@ -81,9 +83,10 @@ export default function getPathFromState<ParamList extends {}>(
}

// Create a normalized configs object which will be easier to use
- const configs: Record<string, ConfigItem> = options?.screens
- ? createNormalizedConfigs(options?.screens)
- : {};
+ if (cachedNormalizedConfigsRef[0] !== options?.screens) {
+ cachedNormalizedConfigsRef = [options?.screens, options?.screens ? createNormalizedConfigs(options.screens) : {}];
+ }
+ const configs: Record<string, ConfigItem> = cachedNormalizedConfigsRef[1];

let path = '/';
let current: State | undefined = state;

0 comments on commit 2ef46bd

Please sign in to comment.