From 3281087213e9055cad78d095a22cc84c34ea557d Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Sat, 8 Jun 2024 00:13:55 -0400 Subject: [PATCH] Use the name of the inner most parent for messages --- .../src/getComponentNameFromFiber.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/react-reconciler/src/getComponentNameFromFiber.js b/packages/react-reconciler/src/getComponentNameFromFiber.js index 332324900fa88..d8b5269d87ad5 100644 --- a/packages/react-reconciler/src/getComponentNameFromFiber.js +++ b/packages/react-reconciler/src/getComponentNameFromFiber.js @@ -44,6 +44,7 @@ import { LegacyHiddenComponent, CacheComponent, TracingMarkerComponent, + Throw, } from 'react-reconciler/src/ReactWorkTags'; import getComponentNameFromType from 'shared/getComponentNameFromType'; import {REACT_STRICT_MODE_TYPE} from 'shared/ReactSymbols'; @@ -160,6 +161,25 @@ export default function getComponentNameFromFiber(fiber: Fiber): string | null { if (enableLegacyHidden) { return 'LegacyHidden'; } + case Throw: { + if (__DEV__) { + // For an error in child position we use the of the inner most parent component. + // Whether a Server Component or the parent Fiber. + const debugInfo = fiber._debugInfo; + if (debugInfo != null) { + for (let i = debugInfo.length - 1; i >= 0; i--) { + if (typeof debugInfo[i].name === 'string') { + return debugInfo[i].name; + } + } + } + if (fiber.return === null) { + return null; + } + return getComponentNameFromFiber(fiber.return); + } + return null; + } } return null;