Skip to content

Commit

Permalink
Fix "Unknown" on deep hook trees
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 3, 2024
1 parent 2a28644 commit 81f4373
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,12 @@ function parseTrimmedStack(rootStack: any, hook: HookLogEntry) {
primitiveIndex === -1 ||
rootIndex - primitiveIndex < 2
) {
// Something went wrong. Give up.
return null;
if (primitiveIndex === -1) {
// Something went wrong. Give up.
return [null, null];
} else {
return [hookStack[primitiveIndex - 1], null];
}
}
return [
hookStack[primitiveIndex - 1],
Expand Down Expand Up @@ -927,16 +931,17 @@ function buildTree(
for (let i = 0; i < readHookLog.length; i++) {
const hook = readHookLog[i];
const parseResult = parseTrimmedStack(rootStack, hook);
const primitiveFrame = parseResult[0];
const stack = parseResult[1];
let displayName = hook.displayName;
if (parseResult !== null) {
const [primitiveFrame, stack] = parseResult;
if (hook.displayName === null) {
displayName =
parseHookName(primitiveFrame.functionName) ||
// Older versions of React do not have sourcemaps.
// In those versions there was always a 1:1 mapping between wrapper and dispatcher method.
parseHookName(hook.dispatcherMethodName);
}
if (displayName === null && primitiveFrame !== null) {
displayName =
parseHookName(primitiveFrame.functionName) ||
// Older versions of React do not have sourcemaps.
// In those versions there was always a 1:1 mapping between wrapper and dispatcher method.
parseHookName(hook.dispatcherMethodName);
}
if (stack !== null) {
// Note: The indices 0 <= n < length-1 will contain the names.
// The indices 1 <= n < length will contain the source locations.
// That's why we get the name from n - 1 and don't check the source
Expand Down Expand Up @@ -1016,7 +1021,6 @@ function buildTree(
fileName: null,
columnNumber: null,
};
const stack = parseResult !== null ? parseResult[1] : null;
if (stack && stack.length >= 1) {
const stackFrame = stack[0];
hookSource.lineNumber = stackFrame.lineNumber;
Expand Down

0 comments on commit 81f4373

Please sign in to comment.