Skip to content

Commit d422a4f

Browse files
committed
Always use includeHooksSource option
This option was added defensively but it's not needed. There's no cost to including it always. I suspect this optional was added mainly to avoid needing to update tests. That's not a reason to have an unnecessary public API though. We have a praxis for dealing with source location in tests to avoid them failing tests.
1 parent 32df74d commit d422a4f

File tree

5 files changed

+2096
-979
lines changed

5 files changed

+2096
-979
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ export type HooksNode = {
570570
value: mixed,
571571
subHooks: Array<HooksNode>,
572572
debugInfo: null | ReactDebugInfo,
573-
hookSource?: HookSource,
573+
hookSource: null | HookSource,
574574
};
575575
export type HooksTree = Array<HooksNode>;
576576

@@ -717,7 +717,6 @@ function parseCustomHookName(functionName: void | string): string {
717717
function buildTree(
718718
rootStack: any,
719719
readHookLog: Array<HookLogEntry>,
720-
includeHooksSource: boolean,
721720
): HooksTree {
722721
const rootChildren: Array<HooksNode> = [];
723722
let prevStack = null;
@@ -761,16 +760,13 @@ function buildTree(
761760
value: undefined,
762761
subHooks: children,
763762
debugInfo: null,
764-
};
765-
766-
if (includeHooksSource) {
767-
levelChild.hookSource = {
763+
hookSource: {
768764
lineNumber: stackFrame.lineNumber,
769765
columnNumber: stackFrame.columnNumber,
770766
functionName: stackFrame.functionName,
771767
fileName: stackFrame.fileName,
772-
};
773-
}
768+
},
769+
};
774770

775771
levelChildren.push(levelChild);
776772
stackOfChildren.push(levelChildren);
@@ -801,26 +797,25 @@ function buildTree(
801797
value: hook.value,
802798
subHooks: [],
803799
debugInfo: debugInfo,
800+
hookSource: null,
804801
};
805802

806-
if (includeHooksSource) {
807-
const hookSource: HookSource = {
808-
lineNumber: null,
809-
functionName: null,
810-
fileName: null,
811-
columnNumber: null,
812-
};
813-
if (stack && stack.length >= 1) {
814-
const stackFrame = stack[0];
815-
hookSource.lineNumber = stackFrame.lineNumber;
816-
hookSource.functionName = stackFrame.functionName;
817-
hookSource.fileName = stackFrame.fileName;
818-
hookSource.columnNumber = stackFrame.columnNumber;
819-
}
820-
821-
levelChild.hookSource = hookSource;
803+
const hookSource: HookSource = {
804+
lineNumber: null,
805+
functionName: null,
806+
fileName: null,
807+
columnNumber: null,
808+
};
809+
if (stack && stack.length >= 1) {
810+
const stackFrame = stack[0];
811+
hookSource.lineNumber = stackFrame.lineNumber;
812+
hookSource.functionName = stackFrame.functionName;
813+
hookSource.fileName = stackFrame.fileName;
814+
hookSource.columnNumber = stackFrame.columnNumber;
822815
}
823816

817+
levelChild.hookSource = hookSource;
818+
824819
levelChildren.push(levelChild);
825820
}
826821

@@ -898,7 +893,6 @@ export function inspectHooks<Props>(
898893
renderFunction: Props => React$Node,
899894
props: Props,
900895
currentDispatcher: ?CurrentDispatcherRef,
901-
includeHooksSource: boolean = false,
902896
): HooksTree {
903897
// DevTools will pass the current renderer's injected dispatcher.
904898
// Other apps might compile debug hooks as part of their app though.
@@ -924,7 +918,7 @@ export function inspectHooks<Props>(
924918
currentDispatcher.current = previousDispatcher;
925919
}
926920
const rootStack = ErrorStackParser.parse(ancestorStackError);
927-
return buildTree(rootStack, readHookLog, includeHooksSource);
921+
return buildTree(rootStack, readHookLog);
928922
}
929923

930924
function setupContexts(contextMap: Map<ReactContext<any>, any>, fiber: Fiber) {
@@ -953,7 +947,6 @@ function inspectHooksOfForwardRef<Props, Ref>(
953947
props: Props,
954948
ref: Ref,
955949
currentDispatcher: CurrentDispatcherRef,
956-
includeHooksSource: boolean,
957950
): HooksTree {
958951
const previousDispatcher = currentDispatcher.current;
959952
let readHookLog;
@@ -970,7 +963,7 @@ function inspectHooksOfForwardRef<Props, Ref>(
970963
currentDispatcher.current = previousDispatcher;
971964
}
972965
const rootStack = ErrorStackParser.parse(ancestorStackError);
973-
return buildTree(rootStack, readHookLog, includeHooksSource);
966+
return buildTree(rootStack, readHookLog);
974967
}
975968

976969
function resolveDefaultProps(Component: any, baseProps: any) {
@@ -991,7 +984,6 @@ function resolveDefaultProps(Component: any, baseProps: any) {
991984
export function inspectHooksOfFiber(
992985
fiber: Fiber,
993986
currentDispatcher: ?CurrentDispatcherRef,
994-
includeHooksSource: boolean = false,
995987
): HooksTree {
996988
// DevTools will pass the current renderer's injected dispatcher.
997989
// Other apps might compile debug hooks as part of their app though.
@@ -1033,11 +1025,10 @@ export function inspectHooksOfFiber(
10331025
props,
10341026
fiber.ref,
10351027
currentDispatcher,
1036-
includeHooksSource,
10371028
);
10381029
}
10391030

1040-
return inspectHooks(type, props, currentDispatcher, includeHooksSource);
1031+
return inspectHooks(type, props, currentDispatcher);
10411032
} finally {
10421033
currentFiber = null;
10431034
currentHook = null;

0 commit comments

Comments
 (0)