Skip to content

Commit ffc3006

Browse files
committed
Fix special case when the function call throws in V8
In V8 we need to ignore the first line. Normally we would never get there because the stacks would differ before that, but the stacks are the same if we end up throwing at the same place as the control.
1 parent 91b5f34 commit ffc3006

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

packages/shared/ReactComponentStackFrame.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,22 @@ export function describeNativeComponentFrame(
129129
// Next we find the first one that isn't the same which should be the
130130
// frame that called our sample function.
131131
if (sampleLines[s] !== controlLines[c]) {
132-
// Return the line we found.
133-
// V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
134-
const frame = '\n' + sampleLines[s - 1].replace(' at new ', ' at ');
135-
if (__DEV__) {
136-
if (typeof fn === 'function') {
137-
componentFrameCache.set(fn, frame);
132+
// In V8, the first line is describing the message but other VMs don't.
133+
// If we're about to return the first line, and the control is also on the same
134+
// line, that's a pretty good indicator that our sample threw at same line as
135+
// the control. I.e. before we entered the sample frame. So we ignore this result.
136+
// This can happen if you passed a class to function component, or non-function.
137+
if (s !== 1 || c !== 1) {
138+
// V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
139+
const frame = '\n' + sampleLines[s - 1].replace(' at new ', ' at ');
140+
if (__DEV__) {
141+
if (typeof fn === 'function') {
142+
componentFrameCache.set(fn, frame);
143+
}
138144
}
145+
// Return the line we found.
146+
return frame;
139147
}
140-
return frame;
141148
}
142149
}
143150
}

0 commit comments

Comments
 (0)