Skip to content

Commit f0e808e

Browse files
authored
[Debug Tools] Always use includeHooksSource option (#28309)
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. I also ported them to inline snapshots so that additions to the protocol isn't such a pain.
1 parent dc31781 commit f0e808e

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
@@ -569,7 +569,7 @@ export type HooksNode = {
569569
value: mixed,
570570
subHooks: Array<HooksNode>,
571571
debugInfo: null | ReactDebugInfo,
572-
hookSource?: HookSource,
572+
hookSource: null | HookSource,
573573
};
574574
export type HooksTree = Array<HooksNode>;
575575

@@ -716,7 +716,6 @@ function parseCustomHookName(functionName: void | string): string {
716716
function buildTree(
717717
rootStack: any,
718718
readHookLog: Array<HookLogEntry>,
719-
includeHooksSource: boolean,
720719
): HooksTree {
721720
const rootChildren: Array<HooksNode> = [];
722721
let prevStack = null;
@@ -760,16 +759,13 @@ function buildTree(
760759
value: undefined,
761760
subHooks: children,
762761
debugInfo: null,
763-
};
764-
765-
if (includeHooksSource) {
766-
levelChild.hookSource = {
762+
hookSource: {
767763
lineNumber: stackFrame.lineNumber,
768764
columnNumber: stackFrame.columnNumber,
769765
functionName: stackFrame.functionName,
770766
fileName: stackFrame.fileName,
771-
};
772-
}
767+
},
768+
};
773769

774770
levelChildren.push(levelChild);
775771
stackOfChildren.push(levelChildren);
@@ -800,26 +796,25 @@ function buildTree(
800796
value: hook.value,
801797
subHooks: [],
802798
debugInfo: debugInfo,
799+
hookSource: null,
803800
};
804801

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

816+
levelChild.hookSource = hookSource;
817+
823818
levelChildren.push(levelChild);
824819
}
825820

@@ -897,7 +892,6 @@ export function inspectHooks<Props>(
897892
renderFunction: Props => React$Node,
898893
props: Props,
899894
currentDispatcher: ?CurrentDispatcherRef,
900-
includeHooksSource: boolean = false,
901895
): HooksTree {
902896
// DevTools will pass the current renderer's injected dispatcher.
903897
// Other apps might compile debug hooks as part of their app though.
@@ -923,7 +917,7 @@ export function inspectHooks<Props>(
923917
currentDispatcher.current = previousDispatcher;
924918
}
925919
const rootStack = ErrorStackParser.parse(ancestorStackError);
926-
return buildTree(rootStack, readHookLog, includeHooksSource);
920+
return buildTree(rootStack, readHookLog);
927921
}
928922

929923
function setupContexts(contextMap: Map<ReactContext<any>, any>, fiber: Fiber) {
@@ -955,7 +949,6 @@ function inspectHooksOfForwardRef<Props, Ref>(
955949
props: Props,
956950
ref: Ref,
957951
currentDispatcher: CurrentDispatcherRef,
958-
includeHooksSource: boolean,
959952
): HooksTree {
960953
const previousDispatcher = currentDispatcher.current;
961954
let readHookLog;
@@ -972,7 +965,7 @@ function inspectHooksOfForwardRef<Props, Ref>(
972965
currentDispatcher.current = previousDispatcher;
973966
}
974967
const rootStack = ErrorStackParser.parse(ancestorStackError);
975-
return buildTree(rootStack, readHookLog, includeHooksSource);
968+
return buildTree(rootStack, readHookLog);
976969
}
977970

978971
function resolveDefaultProps(Component: any, baseProps: any) {
@@ -993,7 +986,6 @@ function resolveDefaultProps(Component: any, baseProps: any) {
993986
export function inspectHooksOfFiber(
994987
fiber: Fiber,
995988
currentDispatcher: ?CurrentDispatcherRef,
996-
includeHooksSource: boolean = false,
997989
): HooksTree {
998990
// DevTools will pass the current renderer's injected dispatcher.
999991
// Other apps might compile debug hooks as part of their app though.
@@ -1035,11 +1027,10 @@ export function inspectHooksOfFiber(
10351027
props,
10361028
fiber.ref,
10371029
currentDispatcher,
1038-
includeHooksSource,
10391030
);
10401031
}
10411032

1042-
return inspectHooks(type, props, currentDispatcher, includeHooksSource);
1033+
return inspectHooks(type, props, currentDispatcher);
10431034
} finally {
10441035
currentFiber = null;
10451036
currentHook = null;

0 commit comments

Comments
 (0)