MCPcopy
hub / github.com/facebook/react / findCommonAncestorIndex

Function findCommonAncestorIndex

packages/react-debug-tools/src/ReactDebugHooks.js:872–894  ·  view source on GitHub ↗
(
  rootStack: ParsedStackFrame[],
  hookStack: ParsedStackFrame[],
)

Source from the content-addressed store, hash-verified

870}
871
872function findCommonAncestorIndex(
873 rootStack: ParsedStackFrame[],
874 hookStack: ParsedStackFrame[],
875) {
876 let rootIndex = findSharedIndex(
877 hookStack,
878 rootStack,
879 mostLikelyAncestorIndex,
880 );
881 if (rootIndex !== -1) {
882 return rootIndex;
883 }
884 // If the most likely one wasn't a hit, try any other frame to see if it is shared.
885 // If that takes more than 5 frames, something probably went wrong.
886 for (let i = 0; i < rootStack.length && i < 5; i++) {
887 rootIndex = findSharedIndex(hookStack, rootStack, i);
888 if (rootIndex !== -1) {
889 mostLikelyAncestorIndex = i;
890 return rootIndex;
891 }
892 }
893 return -1;
894}
895
896function isReactWrapper(functionName: void | string, wrapperName: string) {
897 const hookName = parseHookName(functionName);

Callers 1

parseTrimmedStackFunction · 0.85

Calls 1

findSharedIndexFunction · 0.85

Tested by

no test coverage detected