Skip to content

Commit 0affa54

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Show component code frame, if available (#48785)
Summary: Pull Request resolved: #48785 ## Overview This change adds code frames for component stacks if it differs from the call stack frame. ## Background After adding native stack based stack frames, which we already symbolicate, we had the capability to show a code frame for component stacks as well as the stack frame (if they differ). However, this usually wasn't that useful, because the native component stack was unlikely to be more useful than the component stack (see the comparisons below for key errors). ## Owner stacks With owner stacks the component frame is a lot more useful and in many cases are better at showing the location than the call stack frame. ## Example Screens Before: {F1974436645} After (with owner stacks): {F1974436723} Changelog: [General][Added] - Add owner stack code frames to LogBox Reviewed By: hoxyq Differential Revision: D68285627 fbshipit-source-id: 541cecbd4786fffd1970d2e85e659757e3f81604
1 parent 967ef32 commit 0affa54

File tree

7 files changed

+1172
-232
lines changed

7 files changed

+1172
-232
lines changed

packages/react-native/Libraries/LogBox/Data/LogBoxLog.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class LogBoxLog {
7979
count: number;
8080
level: LogLevel;
8181
codeFrame: ?CodeFrame;
82+
componentCodeFrame: ?CodeFrame;
8283
isComponentError: boolean;
8384
extraData: mixed | void;
8485
symbolicated:
@@ -140,8 +141,18 @@ class LogBoxLog {
140141
}
141142

142143
retrySymbolicate(callback?: (status: SymbolicationStatus) => void): void {
144+
let retry = false;
143145
if (this.symbolicated.status !== 'COMPLETE') {
144146
LogBoxSymbolication.deleteStack(this.stack);
147+
retry = true;
148+
}
149+
if (this.symbolicatedComponentStack.status !== 'COMPLETE') {
150+
LogBoxSymbolication.deleteStack(
151+
convertComponentStateToStack(this.componentStack),
152+
);
153+
retry = true;
154+
}
155+
if (retry) {
145156
this.handleSymbolicate(callback);
146157
}
147158
}
@@ -153,7 +164,10 @@ class LogBoxLog {
153164
}
154165

155166
handleSymbolicate(callback?: (status: SymbolicationStatus) => void): void {
156-
if (this.symbolicated.status !== 'PENDING') {
167+
if (
168+
this.symbolicated.status !== 'PENDING' &&
169+
this.symbolicated.status !== 'COMPLETE'
170+
) {
157171
this.updateStatus(null, null, null, callback);
158172
LogBoxSymbolication.symbolicate(this.stack, this.extraData).then(
159173
data => {
@@ -163,25 +177,30 @@ class LogBoxLog {
163177
this.updateStatus(error, null, null, callback);
164178
},
165179
);
166-
if (this.componentStack != null && this.componentStackType === 'stack') {
167-
this.updateComponentStackStatus(null, null, null, callback);
168-
const componentStackFrames = convertComponentStateToStack(
169-
this.componentStack,
170-
);
171-
LogBoxSymbolication.symbolicate(componentStackFrames, []).then(
172-
data => {
173-
this.updateComponentStackStatus(
174-
null,
175-
convertStackToComponentStack(data.stack),
176-
null,
177-
callback,
178-
);
179-
},
180-
error => {
181-
this.updateComponentStackStatus(error, null, null, callback);
182-
},
183-
);
184-
}
180+
}
181+
if (
182+
this.componentStack != null &&
183+
this.componentStackType === 'stack' &&
184+
this.symbolicatedComponentStack.status !== 'PENDING' &&
185+
this.symbolicatedComponentStack.status !== 'COMPLETE'
186+
) {
187+
this.updateComponentStackStatus(null, null, null, callback);
188+
const componentStackFrames = convertComponentStateToStack(
189+
this.componentStack,
190+
);
191+
LogBoxSymbolication.symbolicate(componentStackFrames, []).then(
192+
data => {
193+
this.updateComponentStackStatus(
194+
null,
195+
convertStackToComponentStack(data.stack),
196+
data?.codeFrame,
197+
callback,
198+
);
199+
},
200+
error => {
201+
this.updateComponentStackStatus(error, null, null, callback);
202+
},
203+
);
185204
}
186205
}
187206

@@ -235,6 +254,9 @@ class LogBoxLog {
235254
status: 'FAILED',
236255
};
237256
} else if (componentStack != null) {
257+
if (codeFrame) {
258+
this.componentCodeFrame = codeFrame;
259+
}
238260
this.symbolicatedComponentStack = {
239261
error: null,
240262
componentStack,

0 commit comments

Comments
 (0)