Skip to content

Commit

Permalink
Format DOM Nesting Warning as Diff View + An Additional Log for Stack…
Browse files Browse the repository at this point in the history
… Trace (#30302)

Currently we're printing parent stacks at the end of DOM nesting even
with owner stacks enabled. That's because the context of parent tree is
relevant for determining why two things are nested. It might not be
sufficient to see the owner stack alone.

I'm trying to get rid of parent stacks and rely on more of the plain
owner stacks or ideally console.createTask. These are generally better
anyway since the exact line for creating the JSX is available. It also
lets you find a parent stack frame that is most relevant e.g. if it's
hidden inside internals.

For DOM nesting there's really only two stacks that are relevant. The
creation of the parent and the creation of the child. Sometimes they're
close enough to be the same thing. Such as for parents that can't have
text children or when the ancestor is the direct parent created at the
same place (same owner).

Sometimes they're far apart. In this case I add a second console.error
within the context of the ancestor. That way the second stack trace can
be used to read the stack trace for where it was created.

To preserve some parent context I now print the parent stack in a diff
view format using the logic from hydration diffs. This includes some
siblings and props for context.

<img width="756" alt="Screenshot 2024-07-10 at 12 21 38 AM"
src="https://github.com/facebook/react/assets/63648/0843133d-cc7a-4ecc-91c0-f46ae8e99f20">

Text Nodes:

<img width="749" alt="Screenshot 2024-07-10 at 12 37 40 AM"
src="https://github.com/facebook/react/assets/63648/ee377d82-54ee-450a-99d1-fcc3ef290d59">

---------

Co-authored-by: tjallingt <[email protected]>

DiffTrain build for [2d3f81b](2d3f81b)
  • Loading branch information
sebmarkbage committed Jul 10, 2024
1 parent c8b941f commit f4ccb1f
Show file tree
Hide file tree
Showing 35 changed files with 6,195 additions and 5,902 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
378b305958eb7259cacfce8ad0e66eec07e07074
2d3f81bb6a650386832d885d7b63a7d0d517ba15
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
378b305958eb7259cacfce8ad0e66eec07e07074
2d3f81bb6a650386832d885d7b63a7d0d517ba15
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-378b305958-20240710";
exports.version = "19.0.0-www-classic-2d3f81bb6a-20240710";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-378b305958-20240710";
exports.version = "19.0.0-www-modern-2d3f81bb6a-20240710";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-378b305958-20240710";
exports.version = "19.0.0-www-classic-2d3f81bb6a-20240710";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-378b305958-20240710";
exports.version = "19.0.0-www-modern-2d3f81bb6a-20240710";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-378b305958-20240710";
exports.version = "19.0.0-www-classic-2d3f81bb6a-20240710";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-378b305958-20240710";
exports.version = "19.0.0-www-modern-2d3f81bb6a-20240710";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
32 changes: 22 additions & 10 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,10 @@ __DEV__ &&
"number" === typeof clientProps ||
"bigint" === typeof clientProps
)
content += describeTextDiff("" + clientProps, void 0, indent + 1);
content =
null == type
? content + describeTextDiff("" + clientProps, null, indent + 1)
: content + describeTextDiff("" + clientProps, void 0, indent + 1);
return content;
}
function describeSiblingFiber(fiber, indent) {
Expand Down Expand Up @@ -2027,7 +2030,7 @@ __DEV__ &&
debugInfo = "";
i = node.fiber.pendingProps;
if (6 === node.fiber.tag)
debugInfo = describeTextDiff(i, node.serverProps, indent);
(debugInfo = describeTextDiff(i, node.serverProps, indent)), indent++;
else if (
((serverComponentName = describeFiberType(node.fiber)),
null !== serverComponentName)
Expand Down Expand Up @@ -2055,11 +2058,12 @@ __DEV__ &&
indent++;
} else
null === node.serverProps
? (debugInfo = describeExpandedElement(
? ((debugInfo = describeExpandedElement(
serverComponentName,
i,
added(indent)
))
)),
indent++)
: "string" === typeof node.serverProps
? error$jscomp$0(
"Should not have matched a non HostText fiber to a Text node. This is a bug in React."
Expand Down Expand Up @@ -2087,9 +2091,10 @@ __DEV__ &&
i &&
0 < node.children.length &&
(propName += indentation(indent) + "...\n");
node = node.serverTail;
for (i = 0; i < node.length; i++)
(serverComponentName = node[i]),
i = node.serverTail;
null === node.serverProps && indent--;
for (node = 0; node < i.length; node++)
(serverComponentName = i[node]),
(propName =
"string" === typeof serverComponentName
? propName +
Expand Down Expand Up @@ -2982,6 +2987,7 @@ __DEV__ &&
lanes
)),
(current.return = returnFiber),
(current._debugOwner = returnFiber),
(current._debugInfo = currentDebugInfo),
current
);
Expand Down Expand Up @@ -3055,6 +3061,7 @@ __DEV__ &&
key
)),
(current.return = returnFiber),
(current._debugOwner = returnFiber),
(current._debugInfo = currentDebugInfo),
current
);
Expand All @@ -3076,6 +3083,7 @@ __DEV__ &&
lanes
)),
(newChild.return = returnFiber),
(newChild._debugOwner = returnFiber),
(newChild._debugInfo = currentDebugInfo),
newChild
);
Expand Down Expand Up @@ -3122,6 +3130,7 @@ __DEV__ &&
null
)),
(lanes.return = returnFiber),
(lanes._debugOwner = returnFiber),
(returnFiber = pushDebugInfo(newChild._debugInfo)),
(lanes._debugInfo = currentDebugInfo),
(currentDebugInfo = returnFiber),
Expand Down Expand Up @@ -3654,6 +3663,7 @@ __DEV__ &&
newChild.key
)),
(currentFirstChild.return = returnFiber),
(currentFirstChild._debugOwner = returnFiber),
(currentFirstChild._debugInfo = currentDebugInfo),
validateFragmentProps(
newChild,
Expand Down Expand Up @@ -3825,6 +3835,8 @@ __DEV__ &&
lanes
)),
(currentFirstChild.return = returnFiber),
(currentFirstChild._debugOwner = returnFiber),
(currentFirstChild._debugInfo = currentDebugInfo),
(returnFiber = currentFirstChild)),
placeSingleChild(returnFiber)
);
Expand Down Expand Up @@ -15050,7 +15062,7 @@ __DEV__ &&
_currentValue2: null,
_threadCount: 0
},
needsEscaping = /["'&<>\n\t]/,
needsEscaping = /["'&<>\n\t]|^\s|\s$/,
hydrationDiffRootDEV = null,
hydrationErrors = null,
concurrentQueues = [],
Expand Down Expand Up @@ -16962,14 +16974,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-classic-378b305958-20240710"
reconcilerVersion: "19.0.0-www-classic-2d3f81bb6a-20240710"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-classic-378b305958-20240710",
version: "19.0.0-www-classic-2d3f81bb6a-20240710",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
32 changes: 22 additions & 10 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,10 @@ __DEV__ &&
"number" === typeof clientProps ||
"bigint" === typeof clientProps
)
content += describeTextDiff("" + clientProps, void 0, indent + 1);
content =
null == type
? content + describeTextDiff("" + clientProps, null, indent + 1)
: content + describeTextDiff("" + clientProps, void 0, indent + 1);
return content;
}
function describeSiblingFiber(fiber, indent) {
Expand Down Expand Up @@ -1930,7 +1933,7 @@ __DEV__ &&
debugInfo = "";
i = node.fiber.pendingProps;
if (6 === node.fiber.tag)
debugInfo = describeTextDiff(i, node.serverProps, indent);
(debugInfo = describeTextDiff(i, node.serverProps, indent)), indent++;
else if (
((serverComponentName = describeFiberType(node.fiber)),
null !== serverComponentName)
Expand Down Expand Up @@ -1958,11 +1961,12 @@ __DEV__ &&
indent++;
} else
null === node.serverProps
? (debugInfo = describeExpandedElement(
? ((debugInfo = describeExpandedElement(
serverComponentName,
i,
added(indent)
))
)),
indent++)
: "string" === typeof node.serverProps
? error$jscomp$0(
"Should not have matched a non HostText fiber to a Text node. This is a bug in React."
Expand Down Expand Up @@ -1990,9 +1994,10 @@ __DEV__ &&
i &&
0 < node.children.length &&
(propName += indentation(indent) + "...\n");
node = node.serverTail;
for (i = 0; i < node.length; i++)
(serverComponentName = node[i]),
i = node.serverTail;
null === node.serverProps && indent--;
for (node = 0; node < i.length; node++)
(serverComponentName = i[node]),
(propName =
"string" === typeof serverComponentName
? propName +
Expand Down Expand Up @@ -2881,6 +2886,7 @@ __DEV__ &&
lanes
)),
(current.return = returnFiber),
(current._debugOwner = returnFiber),
(current._debugInfo = currentDebugInfo),
current
);
Expand Down Expand Up @@ -2954,6 +2960,7 @@ __DEV__ &&
key
)),
(current.return = returnFiber),
(current._debugOwner = returnFiber),
(current._debugInfo = currentDebugInfo),
current
);
Expand All @@ -2975,6 +2982,7 @@ __DEV__ &&
lanes
)),
(newChild.return = returnFiber),
(newChild._debugOwner = returnFiber),
(newChild._debugInfo = currentDebugInfo),
newChild
);
Expand Down Expand Up @@ -3021,6 +3029,7 @@ __DEV__ &&
null
)),
(lanes.return = returnFiber),
(lanes._debugOwner = returnFiber),
(returnFiber = pushDebugInfo(newChild._debugInfo)),
(lanes._debugInfo = currentDebugInfo),
(currentDebugInfo = returnFiber),
Expand Down Expand Up @@ -3553,6 +3562,7 @@ __DEV__ &&
newChild.key
)),
(currentFirstChild.return = returnFiber),
(currentFirstChild._debugOwner = returnFiber),
(currentFirstChild._debugInfo = currentDebugInfo),
validateFragmentProps(
newChild,
Expand Down Expand Up @@ -3724,6 +3734,8 @@ __DEV__ &&
lanes
)),
(currentFirstChild.return = returnFiber),
(currentFirstChild._debugOwner = returnFiber),
(currentFirstChild._debugInfo = currentDebugInfo),
(returnFiber = currentFirstChild)),
placeSingleChild(returnFiber)
);
Expand Down Expand Up @@ -14467,7 +14479,7 @@ __DEV__ &&
_currentValue2: null,
_threadCount: 0
},
needsEscaping = /["'&<>\n\t]/,
needsEscaping = /["'&<>\n\t]|^\s|\s$/,
hydrationDiffRootDEV = null,
hydrationErrors = null,
concurrentQueues = [],
Expand Down Expand Up @@ -16377,14 +16389,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-modern-378b305958-20240710"
reconcilerVersion: "19.0.0-www-modern-2d3f81bb6a-20240710"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-modern-378b305958-20240710",
version: "19.0.0-www-modern-2d3f81bb6a-20240710",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10718,7 +10718,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-classic-378b305958-20240710",
version: "19.0.0-www-classic-2d3f81bb6a-20240710",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1386 = {
Expand Down Expand Up @@ -10749,7 +10749,7 @@ var internals$jscomp$inline_1386 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-classic-378b305958-20240710"
reconcilerVersion: "19.0.0-www-classic-2d3f81bb6a-20240710"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1387 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10171,7 +10171,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-modern-378b305958-20240710",
version: "19.0.0-www-modern-2d3f81bb6a-20240710",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1372 = {
Expand Down Expand Up @@ -10202,7 +10202,7 @@ var internals$jscomp$inline_1372 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-modern-378b305958-20240710"
reconcilerVersion: "19.0.0-www-modern-2d3f81bb6a-20240710"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1373 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Loading

0 comments on commit f4ccb1f

Please sign in to comment.