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

Function findPrimitiveIndex

packages/react-debug-tools/src/ReactDebugHooks.js:905–934  ·  view source on GitHub ↗
(hookStack: ParsedStackFrame[], hook: HookLogEntry)

Source from the content-addressed store, hash-verified

903}
904
905function findPrimitiveIndex(hookStack: ParsedStackFrame[], hook: HookLogEntry) {
906 const stackCache = getPrimitiveStackCache();
907 const primitiveStack = stackCache.get(hook.primitive);
908 if (primitiveStack === undefined) {
909 return -1;
910 }
911 for (let i = 0; i < primitiveStack.length && i < hookStack.length; i++) {
912 // Note: there is no guarantee that we will find the top-most primitive frame in the stack
913 // For React Native (uses Hermes), these source fields will be identical and skipped
914 if (primitiveStack[i].source !== hookStack[i].source) {
915 // If the next two frames are functions called `useX` then we assume that they're part of the
916 // wrappers that the React package or other packages adds around the dispatcher.
917 if (
918 i < hookStack.length - 1 &&
919 isReactWrapper(hookStack[i].functionName, hook.dispatcherHookName)
920 ) {
921 i++;
922 }
923 if (
924 i < hookStack.length - 1 &&
925 isReactWrapper(hookStack[i].functionName, hook.dispatcherHookName)
926 ) {
927 i++;
928 }
929
930 return i;
931 }
932 }
933 return -1;
934}
935
936function parseTrimmedStack(rootStack: ParsedStackFrame[], hook: HookLogEntry) {
937 // Get the stack trace between the primitive hook function and

Callers 1

parseTrimmedStackFunction · 0.85

Calls 3

getPrimitiveStackCacheFunction · 0.85
isReactWrapperFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected