Skip to content

Commit 965d2d8

Browse files
committed
Infer a better name from the stack if we only have "Promise"
We do this in the front end so that we have the option to apply source maps and ignore listing in determining this name.
1 parent bd50e9c commit 965d2d8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementSuspendedBy.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ function SuspendedByRow({
8181
}: RowProps) {
8282
const [isOpen, setIsOpen] = useState(false);
8383
const ioInfo = asyncInfo.awaited;
84-
const name = ioInfo.name;
84+
let name = ioInfo.name;
85+
if (name === '' || name === 'Promise') {
86+
// If all we have is a generic name, we can try to infer a better name from
87+
// the stack. We only do this if the stack has more than one frame since
88+
// otherwise it's likely to just be the name of the component which isn't better.
89+
const bestStack = ioInfo.stack || asyncInfo.stack;
90+
if (bestStack !== null && bestStack.length > 1) {
91+
// TODO: Ideally we'd get the name from the last ignore listed frame before the
92+
// first visible frame since this is the same algorithm as the Flight server uses.
93+
// Ideally, we'd also get the name from the source mapped entry instead of the
94+
// original entry. However, that would require suspending the immediate display
95+
// of these rows to first do source mapping before we can show the name.
96+
name = bestStack[0][0];
97+
}
98+
}
8599
const description = ioInfo.description;
86100
const longName = description === '' ? name : name + ' (' + description + ')';
87101
const shortDescription = getShortDescription(name, description);

0 commit comments

Comments
 (0)