Remove ComponentStack → Stack conversion (#55228)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55228

LogBox was doing a wasteful round-trip conversion: parseComponentStack converted Stack → ComponentStack, stored it that way, then convertComponentStackToStack converted it back every time it was used.

This eliminates the unnecessary conversion by storing componentStack as Stack directly from the start. The ComponentStack type is removed entirely since it's no longer needed.

Also consolidates duplicate helper functions in LogBoxLog-test.js by removing createStackForComponentStack and createComponentStack, keeping only the createStack helper.

Changelog: [Internal]

Reviewed By: vzaidman

Differential Revision: D90896380

fbshipit-source-id: d7a0bd07463760470dba7a1aa45df870c1ecd10a
This commit is contained in:
Rick Hanlon authored and meta-codesync[bot] committed 2026-01-28 16:24:16 -08:00
1 parent 7eb3428607
commit f56f942751
12 files changed
+283 -337

No files matched your search

+3 -7
View File
@@ -10,12 +10,8 @@
import type {ExtendedError} from '../../Core/ExtendedError';
import type {LogLevel} from './LogBoxLog';
import type {
Category,
ComponentStack,
ExtendedExceptionData,
Message,
} from './parseLogBoxLog';
import type {Stack} from './LogBoxSymbolication';
import type {Category, ExtendedExceptionData, Message} from './parseLogBoxLog';
import DebuggerSessionObserver from '../../../src/private/devsupport/rndevtools/FuseboxSessionObserver';
import toExtendedError from '../../../src/private/utilities/toExtendedError';
@@ -30,7 +26,7 @@ export type LogData = Readonly<{
level: LogLevel,
message: Message,
category: Category,
componentStack: ComponentStack,
componentStack: Stack,
stack?: string,
}>;
+18 -61
View File
@@ -9,12 +9,7 @@
*/
import type {Stack} from './LogBoxSymbolication';
import type {
Category,
CodeFrame,
ComponentStack,
Message,
} from './parseLogBoxLog';
import type {Category, CodeFrame, Message} from './parseLogBoxLog';
import * as LogBoxSymbolication from './LogBoxSymbolication';
@@ -22,45 +17,13 @@ type SymbolicationStatus = 'NONE' | 'PENDING' | 'COMPLETE' | 'FAILED';
export type LogLevel = 'warn' | 'error' | 'fatal' | 'syntax';
// TODO: once component stacks are fully supported, we can refactor
// ComponentStack to just be Stack and remove these conversions fns.
function convertComponentStateToStack(componentStack: ComponentStack): Stack {
return componentStack.map(frame => ({
column: frame?.location?.column,
file: frame.fileName,
lineNumber: frame?.location?.row,
methodName: frame.content,
collapse: false,
}));
}
function convertStackToComponentStack(stack: Stack): ComponentStack {
const componentStack = [];
for (let i = 0; i < stack.length; i++) {
const frame = stack[i];
// NOTE: Skip stack frames missing location.
if (frame.lineNumber != null && frame.column != null) {
componentStack.push({
fileName: frame?.file || '',
location: {
row: frame.lineNumber,
column: frame.column,
},
content: frame.methodName,
collapse: false,
});
}
}
return componentStack;
}
export type LogBoxLogData = Readonly<{
level: LogLevel,
type?: ?string,
message: Message,
stack: Stack,
category: string,
componentStack: ComponentStack,
componentStack: Stack,
codeFrame?: ?CodeFrame,
isComponentError: boolean,
extraData?: unknown,
@@ -71,7 +34,7 @@ class LogBoxLog {
message: Message;
type: ?string;
category: Category;
componentStack: ComponentStack;
componentStack: Stack;
stack: Stack;
count: number;
level: LogLevel;
@@ -89,16 +52,16 @@ class LogBoxLog {
status: 'NONE',
};
symbolicatedComponentStack:
| Readonly<{error: null, componentStack: null, status: 'NONE'}>
| Readonly<{error: null, componentStack: null, status: 'PENDING'}>
| Readonly<{error: null, stack: null, status: 'NONE'}>
| Readonly<{error: null, stack: null, status: 'PENDING'}>
| Readonly<{
error: null,
componentStack: ComponentStack,
stack: Stack,
status: 'COMPLETE',
}>
| Readonly<{error: Error, componentStack: null, status: 'FAILED'}> = {
| Readonly<{error: Error, stack: null, status: 'FAILED'}> = {
error: null,
componentStack: null,
stack: null,
status: 'NONE',
};
onNotificationPress: ?() => void;
@@ -127,9 +90,9 @@ class LogBoxLog {
: this.stack;
}
getAvailableComponentStack(): ComponentStack {
getAvailableComponentStack(): Stack {
return this.symbolicatedComponentStack.status === 'COMPLETE'
? this.symbolicatedComponentStack.componentStack
? this.symbolicatedComponentStack.stack
: this.componentStack;
}
@@ -140,9 +103,7 @@ class LogBoxLog {
retry = true;
}
if (this.symbolicatedComponentStack.status !== 'COMPLETE') {
LogBoxSymbolication.deleteStack(
convertComponentStateToStack(this.componentStack),
);
LogBoxSymbolication.deleteStack(this.componentStack);
retry = true;
}
if (retry) {
@@ -178,15 +139,11 @@ class LogBoxLog {
this.symbolicatedComponentStack.status !== 'COMPLETE'
) {
this.updateComponentStackStatus(null, null, null, callback);
const componentStackFrames = convertComponentStateToStack(
this.componentStack,
);
LogBoxSymbolication.symbolicate(componentStackFrames, []).then(
LogBoxSymbolication.symbolicate(this.componentStack, []).then(
data => {
this.updateComponentStackStatus(
null,
// TODO: we shouldn't need to convert back to ComponentStack any more
convertStackToComponentStack(data.stack),
data.stack,
data?.codeFrame,
callback,
);
@@ -236,7 +193,7 @@ class LogBoxLog {
updateComponentStackStatus(
error: ?Error,
componentStack: ?ComponentStack,
stack: ?Stack,
codeFrame: ?CodeFrame,
callback?: (status: SymbolicationStatus) => void,
): void {
@@ -244,22 +201,22 @@ class LogBoxLog {
if (error != null) {
this.symbolicatedComponentStack = {
error,
componentStack: null,
stack: null,
status: 'FAILED',
};
} else if (componentStack != null) {
} else if (stack != null) {
if (codeFrame) {
this.componentCodeFrame = codeFrame;
}
this.symbolicatedComponentStack = {
error: null,
componentStack,
stack,
status: 'COMPLETE',
};
} else {
this.symbolicatedComponentStack = {
error: null,
componentStack: null,
stack: null,
status: 'PENDING',
};
}
@@ -12,7 +12,6 @@
import type {SymbolicatedStackTrace} from '../../../Core/Devtools/symbolicateStackTrace';
import type {StackFrame} from '../../../Core/NativeExceptionsManager';
import type {CodeFrame} from '../parseLogBoxLog';
jest.mock('../LogBoxSymbolication', () => {
return {__esModule: true, symbolicate: jest.fn(), deleteStack: jest.fn()};
@@ -69,7 +68,7 @@ const createStack = (methodNames: Array<string>) =>
methodName,
}));
const createStackForComponentStack = (methodNames: Array<string>) =>
const createComponentStack = (methodNames: Array<string>) =>
methodNames.map((methodName): StackFrame => ({
column: 0,
file: 'file://path/to/component.js',
@@ -77,17 +76,6 @@ const createStackForComponentStack = (methodNames: Array<string>) =>
methodName,
}));
const createComponentStack = (methodNames: Array<string>) =>
methodNames.map((methodName): CodeFrame => ({
collapse: false,
content: methodName,
location: {
row: 1,
column: 0,
},
fileName: 'file://path/to/component.js',
}));
function mockSymbolicate(
stack: ReadonlyArray<StackFrame>,
stackCodeFrame: ?CodeCodeFrame,
@@ -100,9 +88,7 @@ function mockSymbolicate(
firstFrame.file.indexOf('component.js') > 0
) {
return {
stack: createStackForComponentStack(
stack.map(frame => `C(${frame.methodName})`),
),
stack: createStack(stack.map(frame => `C(${frame.methodName})`)),
codeFrame: COMPONENT_CODE_FRAME,
};
}
@@ -157,7 +143,7 @@ describe('LogBoxLog', () => {
});
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: null,
stack: null,
status: 'NONE',
});
});
@@ -179,7 +165,7 @@ describe('LogBoxLog', () => {
});
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: null,
stack: null,
status: 'PENDING',
});
@@ -216,7 +202,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
expect(log.componentCodeFrame).toBe(COMPONENT_CODE_FRAME);
@@ -266,7 +252,7 @@ describe('LogBoxLog', () => {
});
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
@@ -318,7 +304,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error,
componentStack: null,
stack: null,
status: 'FAILED',
});
@@ -351,7 +337,7 @@ describe('LogBoxLog', () => {
});
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: null,
stack: null,
status: 'PENDING',
});
@@ -388,7 +374,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
expect(log.componentCodeFrame).toBe(COMPONENT_CODE_FRAME);
@@ -432,7 +418,7 @@ describe('LogBoxLog', () => {
});
expect(log.symbolicatedComponentStack).toEqual({
error,
componentStack: null,
stack: null,
status: 'FAILED',
});
@@ -463,7 +449,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
expect(log.componentCodeFrame).toBe(COMPONENT_CODE_FRAME);
@@ -502,7 +488,7 @@ describe('LogBoxLog', () => {
});
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
expect(log.componentCodeFrame).toBe(COMPONENT_CODE_FRAME);
@@ -534,7 +520,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
expect(log.componentCodeFrame).toBe(COMPONENT_CODE_FRAME);
@@ -574,7 +560,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error,
componentStack: null,
stack: null,
status: 'FAILED',
});
@@ -605,7 +591,7 @@ describe('LogBoxLog', () => {
expect(log.codeFrame).toBe(STACK_CODE_FRAME);
expect(log.symbolicatedComponentStack).toEqual({
error: null,
componentStack: createComponentStack(['C(A)', 'C(B)', 'C(C)']),
stack: createStack(['C(A)', 'C(B)', 'C(C)']),
status: 'COMPLETE',
});
expect(log.componentCodeFrame).toBe(COMPONENT_CODE_FRAME);
@@ -538,18 +538,18 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
// TODO: we're missing the second component,
// because React isn't sending back a properly formatted stackframe.
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category:
@@ -575,16 +575,18 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
// TODO: we're missing the second component,
// because React isn't sending back a properly formatted stackframe.
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category: 'Some kind of message',
@@ -604,16 +606,18 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
// TODO: we're missing the second component,
// because React isn't sending back a properly formatted stackframe.
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category: 'Some kind of message',
@@ -635,18 +639,18 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
// TODO: we're missing the second component,
// because React isn't sending back a properly formatted stackframe.
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category:
@@ -699,20 +703,21 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
},
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
// TODO: we're missing the second component,
// because React isn't sending back a properly formatted stackframe.
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
extraData: undefined,
stack: [
{
column: 1,
@@ -738,22 +743,25 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
arguments: [],
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
{
collapse: false,
content: 'forEach',
fileName: '[native code]',
location: {column: -1, row: -1},
arguments: [],
methodName: 'forEach',
file: '[native code]',
lineNumber: null,
column: null,
},
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
arguments: [],
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category:
@@ -779,22 +787,25 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
arguments: [],
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
{
collapse: false,
content: 'forEach',
fileName: '[native code]',
location: {column: -1, row: -1},
arguments: [],
methodName: 'forEach',
file: '[native code]',
lineNumber: null,
column: null,
},
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
arguments: [],
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category: 'Some kind of message',
@@ -813,40 +824,32 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyTSComponent',
fileName: '/path/to/MyTSComponent.ts',
location: {
column: 0,
row: 1,
},
arguments: [],
methodName: 'MyTSComponent',
file: '/path/to/MyTSComponent.ts',
lineNumber: 1,
column: 0,
},
{
collapse: false,
content: 'MyTSXComponent',
fileName: '/path/to/MyTSXComponent.tsx',
location: {
column: 0,
row: 2,
},
arguments: [],
methodName: 'MyTSXComponent',
file: '/path/to/MyTSXComponent.tsx',
lineNumber: 2,
column: 0,
},
{
collapse: false,
content: 'MyJSXComponent',
fileName: '/path/to/MyJSXComponent.jsx',
location: {
column: 0,
row: 3,
},
arguments: [],
methodName: 'MyJSXComponent',
file: '/path/to/MyJSXComponent.jsx',
lineNumber: 3,
column: 0,
},
{
collapse: false,
content: 'MyJSComponent',
fileName: '/path/to/MyJSComponent.js',
location: {
column: 0,
row: 4,
},
arguments: [],
methodName: 'MyJSComponent',
file: '/path/to/MyJSComponent.js',
lineNumber: 4,
column: 0,
},
],
category: 'Some kind of message',
@@ -866,22 +869,25 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
arguments: [],
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
{
collapse: false,
content: 'forEach',
fileName: '[native code]',
location: {column: -1, row: -1},
arguments: [],
methodName: 'forEach',
file: '[native code]',
lineNumber: null,
column: null,
},
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
arguments: [],
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category: 'Some kind of message',
@@ -903,22 +909,25 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
).toEqual({
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
arguments: [],
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
{
collapse: false,
content: 'forEach',
fileName: '[native code]',
location: {column: -1, row: -1},
arguments: [],
methodName: 'forEach',
file: '[native code]',
lineNumber: null,
column: null,
},
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
arguments: [],
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
category:
@@ -971,24 +980,28 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
},
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
arguments: [],
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
{
collapse: false,
content: 'forEach',
fileName: '[native code]',
location: {column: -1, row: -1},
arguments: [],
methodName: 'forEach',
file: '[native code]',
lineNumber: null,
column: null,
},
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
arguments: [],
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
extraData: undefined,
stack: [
{
column: 1,
@@ -1036,24 +1049,28 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
],
componentStack: [
{
collapse: false,
content: 'MyComponent',
fileName: '/path/to/filename.js',
location: {column: 1, row: 1},
arguments: [],
methodName: 'MyComponent',
file: '/path/to/filename.js',
lineNumber: 1,
column: 1,
},
{
collapse: false,
content: 'forEach',
fileName: '[native code]',
location: {column: -1, row: -1},
arguments: [],
methodName: 'forEach',
file: '[native code]',
lineNumber: null,
column: null,
},
{
collapse: false,
content: 'MyAppComponent',
fileName: '/path/to/app.js',
location: {column: 19, row: 100},
arguments: [],
methodName: 'MyAppComponent',
file: '/path/to/app.js',
lineNumber: 100,
column: 19,
},
],
extraData: undefined,
category: 'Some kind of message',
message: {
content: 'Some kind of message',
@@ -10,6 +10,7 @@
import type {ExceptionData} from '../../Core/NativeExceptionsManager';
import type {LogBoxLogData} from './LogBoxLog';
import type {Stack} from './LogBoxSymbolication';
import parseErrorStack from '../../Core/Devtools/parseErrorStack';
import UTFSequence from '../../UTFSequence';
@@ -76,15 +77,6 @@ const RE_BABEL_CODE_FRAME_MARKER_PATTERN = new RegExp(
'm',
);
export function hasComponentStack(args: ReadonlyArray<unknown>): boolean {
for (const arg of args) {
if (typeof arg === 'string' && isComponentStack(arg)) {
return true;
}
}
return false;
}
export type ExtendedExceptionData = ExceptionData & {
isComponentError: boolean,
...
@@ -114,8 +106,6 @@ export type Message = Readonly<{
>,
}>;
export type ComponentStack = ReadonlyArray<CodeFrame>;
const SUBSTITUTION = UTFSequence.BOM + '%s';
export function parseInterpolation(args: ReadonlyArray<unknown>): Readonly<{
@@ -204,24 +194,11 @@ function isComponentStack(consoleArgument: string) {
}
export function parseComponentStack(message: string): {
stack: ComponentStack,
stack: Stack,
} {
// Component stacks are formatted as call stack frames.
// Parse the component stack using the error stack parser.
const stack = parseErrorStack(message);
return {
stack:
stack && stack.length > 0
? stack.map(frame => ({
content: frame.methodName,
collapse: frame.collapse || false,
fileName: frame.file == null ? 'unknown' : frame.file,
location: {
column: frame.column == null ? -1 : frame.column,
row: frame.lineNumber == null ? -1 : frame.lineNumber,
},
}))
: [],
stack: stack ?? [],
};
}
@@ -391,13 +368,13 @@ export function withoutANSIColorStyles(message: unknown): unknown {
}
export function parseLogBoxLog(args: ReadonlyArray<unknown>): {
componentStack: ComponentStack,
componentStack: Stack,
category: Category,
message: Message,
} {
const message = withoutANSIColorStyles(args[0]);
let argsWithoutComponentStack: Array<unknown> = [];
let componentStack: ComponentStack = [];
let componentStack: Stack = [];
// Extract component stack from warnings like "Some warning%s".
if (
+32 -1
View File
@@ -9,6 +9,7 @@
*/
import type {IgnorePattern, LogData} from './Data/LogBoxData';
import type {Stack} from './Data/LogBoxSymbolication';
import type {ExtendedExceptionData} from './Data/parseLogBoxLog';
import toExtendedError from '../../src/private/utilities/toExtendedError';
@@ -16,6 +17,33 @@ import Platform from '../Utilities/Platform';
import RCTLog from '../Utilities/RCTLog';
import * as React from 'react';
// TODO: Remove support for LegacyComponentStackFrame in a future version.
// This is kept for backward compatibility with external callers of LogBox.addLog.
function convertLegacyComponentStack(componentStack: Stack): Stack {
if (componentStack.length === 0) {
return [];
}
// Detect legacy format by checking for 'content' property
const firstFrame = componentStack[0];
if (
firstFrame != null &&
typeof firstFrame === 'object' &&
// $FlowExpectedError[prop-missing]
typeof firstFrame.content === 'string'
) {
// Convert from legacy ComponentStack to Stack format
return (componentStack: $FlowFixMe).map(frame => ({
methodName: frame.content,
lineNumber: frame.location.row,
column: frame.location.column,
file: frame.fileName,
collapse: frame.collapse ?? false,
}));
}
// Already in the new Stack format
return componentStack;
}
export type {LogData, ExtendedExceptionData, IgnorePattern};
let LogBox;
@@ -137,7 +165,10 @@ if (__DEV__) {
addLog(log: LogData): void {
if (isLogBoxInstalled) {
LogBoxData.addLog(log);
LogBoxData.addLog({
...log,
componentStack: convertLegacyComponentStack(log.componentStack),
});
}
},
@@ -95,9 +95,9 @@ function LogBoxInspectorReactFrames(props: Props): React.Node {
// Older versions of DevTools do not provide full path.
// This will not work on Windows, remove check once the
// DevTools return the full file path.
frame.fileName.startsWith('/')
frame.file != null && frame.file.startsWith('/')
? () =>
openFileInEditor(frame.fileName, frame.location?.row ?? 1)
openFileInEditor(frame.file ?? '', frame.lineNumber ?? 1)
: null
}
style={componentStyles.frame}>
@@ -106,13 +106,13 @@ function LogBoxInspectorReactFrames(props: Props): React.Node {
id="logbox_component_stack_frame_text"
style={componentStyles.frameName}>
<Text style={componentStyles.bracket}>{'<'}</Text>
{frame.content}
{frame.methodName}
<Text style={componentStyles.bracket}>{' />'}</Text>
</Text>
</View>
<Text style={componentStyles.frameLocation}>
{getPrettyFileName(frame.fileName)}
{frame.location ? `:${frame.location.row}` : ''}
{frame.file != null ? getPrettyFileName(frame.file) : ''}
{frame.lineNumber != null ? `:${frame.lineNumber}` : ''}
</Text>
</LogBoxButton>
</View>
@@ -65,12 +65,11 @@ describe('LogBoxInspectorReactFrames', () => {
category: 'Some kind of message',
componentStack: [
{
content: 'MyComponent',
fileName: 'MyComponentFile.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent',
file: 'MyComponentFile.js',
lineNumber: 1,
column: -1,
collapse: false,
},
],
})
@@ -96,12 +95,11 @@ describe('LogBoxInspectorReactFrames', () => {
category: 'Some kind of message',
componentStack: [
{
content: 'MyComponent',
fileName: '/path/to/MyComponentFile.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent',
file: '/path/to/MyComponentFile.js',
lineNumber: 1,
column: -1,
collapse: false,
},
],
})
@@ -127,12 +125,11 @@ describe('LogBoxInspectorReactFrames', () => {
category: 'Some kind of message',
componentStack: [
{
content: 'MyComponent',
fileName: '/path/to/index.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent',
file: '/path/to/index.js',
lineNumber: 1,
column: -1,
collapse: false,
},
],
})
@@ -158,36 +155,32 @@ describe('LogBoxInspectorReactFrames', () => {
category: 'Some kind of message',
componentStack: [
{
content: 'MyComponent',
fileName: '/path/to/index.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent',
file: '/path/to/index.js',
lineNumber: 1,
column: -1,
collapse: false,
},
{
content: 'MyComponent2',
fileName: '/path/to/index2.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent2',
file: '/path/to/index2.js',
lineNumber: 1,
column: -1,
collapse: false,
},
{
content: 'MyComponent3',
fileName: '/path/to/index3.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent3',
file: '/path/to/index3.js',
lineNumber: 1,
column: -1,
collapse: false,
},
{
content: 'MyComponent4',
fileName: '/path/to/index4.js',
location: {
row: 1,
column: -1,
},
methodName: 'MyComponent4',
file: '/path/to/index4.js',
lineNumber: 1,
column: -1,
collapse: false,
},
],
})
@@ -38,8 +38,8 @@ exports[`LogBoxContainer should render fatal with selectedIndex 2 1`] = `
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -95,8 +95,8 @@ exports[`LogBoxContainer should render warning with selectedIndex 0 1`] = `
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -43,8 +43,8 @@ exports[`LogBoxNotificationContainer should render both an error and warning not
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -87,8 +87,8 @@ exports[`LogBoxNotificationContainer should render both an error and warning not
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -153,8 +153,8 @@ exports[`LogBoxNotificationContainer should render the latest error notification
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -211,8 +211,8 @@ exports[`LogBoxNotificationContainer should render the latest warning notificati
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -35,8 +35,8 @@ exports[`LogBoxNotificationContainer should render inspector with logs, even whe
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
@@ -61,8 +61,8 @@ exports[`LogBoxNotificationContainer should render inspector with logs, even whe
"status": "NONE",
},
"symbolicatedComponentStack": Object {
"componentStack": null,
"error": null,
"stack": null,
"status": "NONE",
},
"type": undefined,
+5 -16
View File
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<5a439f78e7f531211b80923153819de5>>
* @generated SignedSource<<74ac46b82182a7d97e92c933a361f583>>
*
* This file was generated by scripts/js-api/build-types/index.js.
*/
@@ -1834,17 +1834,6 @@ declare class CellRenderMask {
numCells(): number
}
declare type Clipboard = typeof Clipboard
declare type CodeFrame = {
readonly collapse?: boolean
readonly content: string
readonly fileName: string
readonly location:
| undefined
| {
column: number
row: number
}
}
declare type codegenNativeCommands = typeof codegenNativeCommands
declare function codegenNativeCommands_default<T extends {}>(
options: NativeCommandsOptions<keyof T>,
@@ -1876,7 +1865,6 @@ declare type ComponentProviderInstrumentationHook = (
component_: ComponentProvider,
scopedPerformanceLogger: IPerformanceLogger,
) => React.ComponentType<any>
declare type ComponentStack = ReadonlyArray<CodeFrame>
declare type ComponentType = HostComponent<SwitchNativeProps>
declare type compose = typeof compose
declare function composeStyles_default<T, U extends T, V extends T>(
@@ -3105,7 +3093,7 @@ declare type ListViewToken = {
declare type LogBox = typeof LogBox
declare type LogData = {
readonly category: Category
readonly componentStack: ComponentStack
readonly componentStack: Stack
readonly level: LogLevel
readonly message: Message
readonly stack?: string
@@ -4886,6 +4874,7 @@ declare type SpringAnimationConfig = Readonly<
}
}
>
declare type Stack = Array<StackFrame>
declare type StackFrame = {
collapse?: boolean
column: number | undefined
@@ -6102,8 +6091,8 @@ export {
ListRenderItem, // b5353fd8
ListRenderItemInfo, // e8595b03
ListViewToken, // 833d3481
LogBox, // 3be1c25f
LogData, // dc101845
LogBox, // 94d278f1
LogData, // e68f7019
MeasureInWindowOnSuccessCallback, // a285f598
MeasureLayoutOnSuccessCallback, // 3592502a
MeasureOnSuccessCallback, // 82824e59