-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getPathFromState cache normalized configs calculation
- Loading branch information
1 parent
ff948e1
commit 2ef46bd
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
patches/@react-navigation+core+6.4.11+001+cache-getPathFromState normalizedConfigs.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |