Skip to content

Commit e05cc78

Browse files
committed
update debug()
1 parent 01ae2dd commit e05cc78

File tree

1 file changed

+45
-41
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+45
-41
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

+45-41
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,10 @@ export function attach(
10981098
// even if objects are different
10991099
const message = formatConsoleArgumentsToSingleString(...args);
11001100
if (__DEBUG__) {
1101-
debug('onErrorOrWarning', fiber, null, `${type}: "${message}"`);
1101+
const fiberInstance = fiberToFiberInstanceMap.get(fiber);
1102+
if (fiberInstance !== undefined) {
1103+
debug('onErrorOrWarning', fiberInstance, null, `${type}: "${message}"`);
1104+
}
11021105
}
11031106

11041107
// Mark this Fiber as needed its warning/error count updated during the next flush.
@@ -1134,32 +1137,37 @@ export function attach(
11341137
// It relies on the extension to pass the preference through via the global.
11351138
patchConsoleUsingWindowValues();
11361139

1137-
const debug = (
1140+
function debug(
11381141
name: string,
1139-
fiber: Fiber,
1142+
instance: DevToolsInstance,
11401143
parentInstance: null | DevToolsInstance,
11411144
extraString: string = '',
1142-
): void => {
1145+
): void {
11431146
if (__DEBUG__) {
11441147
const displayName =
1145-
fiber.tag + ':' + (getDisplayNameForFiber(fiber) || 'null');
1146-
1147-
const maybeID = getFiberIDUnsafe(fiber) || '<no id>';
1148-
1149-
let parentDisplayName;
1150-
let maybeParentID;
1151-
if (parentInstance !== null && parentInstance.kind === FIBER_INSTANCE) {
1152-
const parentFiber = parentInstance.data;
1153-
parentDisplayName =
1154-
parentFiber.tag +
1155-
':' +
1156-
(getDisplayNameForFiber(parentFiber) || 'null');
1157-
maybeParentID = String(parentInstance.id);
1158-
} else {
1159-
// TODO: Handle VirtualInstance
1160-
parentDisplayName = '';
1161-
maybeParentID = '<no-id>';
1162-
}
1148+
instance.kind === VIRTUAL_INSTANCE
1149+
? instance.data.name || 'null'
1150+
: instance.data.tag +
1151+
':' +
1152+
(getDisplayNameForFiber(instance.data) || 'null');
1153+
1154+
const maybeID =
1155+
instance.kind === FILTERED_FIBER_INSTANCE ? '<no id>' : instance.id;
1156+
1157+
const parentDisplayName =
1158+
parentInstance === null
1159+
? ''
1160+
: parentInstance.kind === VIRTUAL_INSTANCE
1161+
? parentInstance.data.name || 'null'
1162+
: parentInstance.data.tag +
1163+
':' +
1164+
(getDisplayNameForFiber(parentInstance.data) || 'null');
1165+
1166+
const maybeParentID =
1167+
parentInstance === null ||
1168+
parentInstance.kind === FILTERED_FIBER_INSTANCE
1169+
? '<no id>'
1170+
: parentInstance.id;
11631171

11641172
console.groupCollapsed(
11651173
`[renderer] %c${name} %c${displayName} (${maybeID}) %c${
@@ -1173,7 +1181,7 @@ export function attach(
11731181
console.log(new Error().stack.split('\n').slice(1).join('\n'));
11741182
console.groupEnd();
11751183
}
1176-
};
1184+
}
11771185

11781186
// eslint-disable-next-line no-unused-vars
11791187
function debugTree(instance: DevToolsInstance, indent: number = 0) {
@@ -1569,9 +1577,6 @@ export function attach(
15691577
// Removes a Fiber (and its alternate) from the Maps used to track their id.
15701578
// This method should always be called when a Fiber is unmounting.
15711579
function untrackFiber(nearestInstance: DevToolsInstance, fiber: Fiber) {
1572-
if (__DEBUG__) {
1573-
debug('untrackFiber()', fiber, null);
1574-
}
15751580
// TODO: Consider using a WeakMap instead. The only thing where that doesn't work
15761581
// is React Native Paper which tracks tags but that support is eventually going away
15771582
// and can use the old findFiberByHostInstance strategy.
@@ -2245,7 +2250,7 @@ export function attach(
22452250
const id = fiberInstance.id;
22462251

22472252
if (__DEBUG__) {
2248-
debug('recordMount()', fiber, parentInstance);
2253+
debug('recordMount()', fiberInstance, parentInstance);
22492254
}
22502255

22512256
const isProfilingSupported = fiber.hasOwnProperty('treeBaseDuration');
@@ -2422,7 +2427,7 @@ export function attach(
24222427
function recordUnmount(fiberInstance: FiberInstance): void {
24232428
const fiber = fiberInstance.data;
24242429
if (__DEBUG__) {
2425-
debug('recordUnmount()', fiber, null);
2430+
debug('recordUnmount()', fiberInstance, reconcilingParent);
24262431
}
24272432

24282433
if (trackedPathMatchInstance === fiberInstance) {
@@ -2757,15 +2762,14 @@ export function attach(
27572762
fiber: Fiber,
27582763
traceNearestHostComponentUpdate: boolean,
27592764
): void {
2760-
if (__DEBUG__) {
2761-
debug('mountFiberRecursively()', fiber, reconcilingParent);
2762-
}
2763-
27642765
const shouldIncludeInTree = !shouldFilterFiber(fiber);
27652766
let newInstance = null;
27662767
if (shouldIncludeInTree) {
27672768
newInstance = recordMount(fiber, reconcilingParent);
27682769
insertChild(newInstance);
2770+
if (__DEBUG__) {
2771+
debug('mountFiberRecursively()', newInstance, reconcilingParent);
2772+
}
27692773
} else if (
27702774
reconcilingParent !== null &&
27712775
reconcilingParent.kind === VIRTUAL_INSTANCE
@@ -2785,6 +2789,9 @@ export function attach(
27852789

27862790
newInstance = createFilteredFiberInstance(fiber);
27872791
insertChild(newInstance);
2792+
if (__DEBUG__) {
2793+
debug('mountFiberRecursively()', newInstance, reconcilingParent);
2794+
}
27882795
}
27892796

27902797
// If we have the tree selection from previous reload, try to match this Fiber.
@@ -2898,9 +2905,7 @@ export function attach(
28982905
// when we switch from primary to fallback, or deleting a subtree.
28992906
function unmountInstanceRecursively(instance: DevToolsInstance) {
29002907
if (__DEBUG__) {
2901-
if (instance.kind === FIBER_INSTANCE) {
2902-
debug('unmountInstanceRecursively()', instance.data, null);
2903-
}
2908+
debug('unmountInstanceRecursively()', instance, reconcilingParent);
29042909
}
29052910

29062911
const stashedParent = reconcilingParent;
@@ -3034,13 +3039,10 @@ export function attach(
30343039
parentInstance: FiberInstance | VirtualInstance,
30353040
) {
30363041
if (__DEBUG__) {
3037-
if (
3038-
parentInstance.firstChild !== null &&
3039-
parentInstance.firstChild.kind === FIBER_INSTANCE
3040-
) {
3042+
if (parentInstance.firstChild !== null) {
30413043
debug(
30423044
'recordResetChildren()',
3043-
parentInstance.firstChild.data,
3045+
parentInstance.firstChild,
30443046
parentInstance,
30453047
);
30463048
}
@@ -3417,7 +3419,9 @@ export function attach(
34173419
traceNearestHostComponentUpdate: boolean,
34183420
): boolean {
34193421
if (__DEBUG__) {
3420-
debug('updateFiberRecursively()', nextFiber, reconcilingParent);
3422+
if (fiberInstance !== null) {
3423+
debug('updateFiberRecursively()', fiberInstance, reconcilingParent);
3424+
}
34213425
}
34223426

34233427
if (traceUpdatesEnabled) {

0 commit comments

Comments
 (0)