Skip to content

Commit bf3f446

Browse files
committed
Use the name of the inner most parent for messages
1 parent 8706db5 commit bf3f446

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/react-reconciler/src/getComponentNameFromFiber.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
LegacyHiddenComponent,
4545
CacheComponent,
4646
TracingMarkerComponent,
47+
Throw,
4748
} from 'react-reconciler/src/ReactWorkTags';
4849
import getComponentNameFromType from 'shared/getComponentNameFromType';
4950
import {REACT_STRICT_MODE_TYPE} from 'shared/ReactSymbols';
@@ -160,6 +161,26 @@ export default function getComponentNameFromFiber(fiber: Fiber): string | null {
160161
if (enableLegacyHidden) {
161162
return 'LegacyHidden';
162163
}
164+
break;
165+
case Throw: {
166+
if (__DEV__) {
167+
// For an error in child position we use the of the inner most parent component.
168+
// Whether a Server Component or the parent Fiber.
169+
const debugInfo = fiber._debugInfo;
170+
if (debugInfo != null) {
171+
for (let i = debugInfo.length - 1; i >= 0; i--) {
172+
if (typeof debugInfo[i].name === 'string') {
173+
return debugInfo[i].name;
174+
}
175+
}
176+
}
177+
if (fiber.return === null) {
178+
return null;
179+
}
180+
return getComponentNameFromFiber(fiber.return);
181+
}
182+
return null;
183+
}
163184
}
164185

165186
return null;

0 commit comments

Comments
 (0)