@samitouri / QOS-React-2 / commits / 455424dbf3

[devtools] fix: fallback to reading string stack trace when failed (#33700)

Discovered while testing with Hermes.

Ruslan Lesiutin committed Jul 4, 2025 at 15:36 UTC 455424dbf3d46d7e9326a64409de063e8f768848
1 file changed +8 -1
packages/react-devtools-shared/src/backend/utils/index.js
+8 -1
@@ -381,7 +381,7 @@ function collectStackTrace(
381 // $FlowFixMe[prop-missing]
382 typeof callSite.getEnclosingColumnNumber === 'function'
383 ? (callSite: any).getEnclosingColumnNumber()
384 - : callSite.getLineNumber();
384 + : callSite.getColumnNumber();
385 if (!sourceURL || !line || !col) {
386 // Skip eval etc. without source url. They don't have location.
387 continue;
@@ -412,12 +412,19 @@ export function parseSourceFromOwnerStack(error: Error): Source | null {
412 let stack;
413 try {
414 stack = error.stack;
415 + } catch (e) {
416 + // $FlowFixMe[incompatible-type] It does accept undefined.
417 + Error.prepareStackTrace = undefined;
418 + stack = error.stack;
419 } finally {
420 Error.prepareStackTrace = previousPrepare;
421 }
422 if (collectedLocation !== null) {
423 return collectedLocation;
424 }
425 + if (stack == null) {
426 + return null;
427 + }
428 // Fallback to parsing the string form.
429 const componentStack = formatOwnerStackString(stack);
430 return parseSourceFromComponentStack(componentStack);