From dabc7fde6f00603326989d44e78186a9043830f5 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 30 Sep 2021 14:12:52 -0400 Subject: [PATCH] Updated describeNativeComponentFrame() to support displayName in stack frames for newer versions of v8 --- packages/shared/ReactComponentStackFrame.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/shared/ReactComponentStackFrame.js b/packages/shared/ReactComponentStackFrame.js index 0e6b8a03c1258..c101003e569e1 100644 --- a/packages/shared/ReactComponentStackFrame.js +++ b/packages/shared/ReactComponentStackFrame.js @@ -168,7 +168,15 @@ export function describeNativeComponentFrame( // The next one that isn't the same should be our match though. if (c < 0 || sampleLines[s] !== controlLines[c]) { // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier. - const frame = '\n' + sampleLines[s].replace(' at new ', ' at '); + let frame = '\n' + sampleLines[s].replace(' at new ', ' at '); + + // If our component frame is labeled "" + // but we have a user-provided "displayName" + // splice it in to make the stack more readable. + if (fn.displayName && frame.includes('')) { + frame = frame.replace('', fn.displayName); + } + if (__DEV__) { if (typeof fn === 'function') { componentFrameCache.set(fn, frame);