Skip to content

Commit f4e936d

Browse files
committed
Encode enclosing line/column numbers in ReactCallSite
If we don't have the ability to get enclosing line/column we encode it as zero. This will point to the beginning of the file which is likely to cause a miss in source mapping to an identifier which is better since it falls back to getting the name of the function in that case instead.
1 parent dd0eaba commit f4e936d

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

packages/react-client/src/ReactFlightReplyClient.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,16 +1279,16 @@ export function createBoundServerReference<A: Iterable<any>, T>(
12791279
const location = metaData.location;
12801280
if (location) {
12811281
const functionName = metaData.name || '';
1282-
const [, filename, line, col] = location;
1282+
const [, filename, , , enclosingLine, enclosingCol] = location;
12831283
const env = metaData.env || 'Server';
12841284
const sourceMap =
12851285
findSourceMapURL == null ? null : findSourceMapURL(filename, env);
12861286
action = createFakeServerFunction(
12871287
functionName,
12881288
filename,
12891289
sourceMap,
1290-
line,
1291-
col,
1290+
enclosingLine,
1291+
enclosingCol,
12921292
env,
12931293
action,
12941294
);
@@ -1350,10 +1350,11 @@ function parseStackLocation(error: Error): null | ReactCallSite {
13501350
if (filename === '<anonymous>') {
13511351
filename = '';
13521352
}
1353+
// This is really the enclosingLine/Column.
13531354
const line = +(parsed[3] || parsed[6]);
13541355
const col = +(parsed[4] || parsed[7]);
13551356

1356-
return [name, filename, line, col];
1357+
return [name, filename, line, col, line, col];
13571358
}
13581359

13591360
export function createServerReference<A: Iterable<any>, T>(
@@ -1374,7 +1375,7 @@ export function createServerReference<A: Iterable<any>, T>(
13741375
// multiple passes of compilation as long as we can find the final source map.
13751376
const location = parseStackLocation(new Error('react-stack-top-frame'));
13761377
if (location !== null) {
1377-
const [, filename, line, col] = location;
1378+
const [, filename, , , line, col] = location;
13781379
// While the environment that the Server Reference points to can be
13791380
// in any environment, what matters here is where the compiled source
13801381
// is from and that's in the currently executing environment. We hard

packages/react-server/src/ReactFlightStackConfigV8.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function collectStackTrace(
6363
// Skip everything after the bottom frame since it'll be internals.
6464
break;
6565
} else if (callSite.isNative()) {
66-
result.push([name, '', 0, 0]);
66+
result.push([name, '', 0, 0, 0, 0]);
6767
} else {
6868
// We encode complex function calls as if they're part of the function
6969
// name since we cannot simulate the complex ones and they look the same
@@ -88,7 +88,17 @@ function collectStackTrace(
8888
}
8989
const line = callSite.getLineNumber() || 0;
9090
const col = callSite.getColumnNumber() || 0;
91-
result.push([name, filename, line, col]);
91+
const enclosingLine: number =
92+
// $FlowFixMe[prop-missing]
93+
typeof callSite.getEnclosingLineNumber === 'function'
94+
? (callSite: any).getEnclosingLineNumber() || 0
95+
: 0;
96+
const enclosingCol: number =
97+
// $FlowFixMe[prop-missing]
98+
typeof callSite.getEnclosingColumnNumber === 'function'
99+
? (callSite: any).getEnclosingColumnNumber() || 0
100+
: 0;
101+
result.push([name, filename, line, col, enclosingLine, enclosingCol]);
92102
}
93103
}
94104
// At the same time we generate a string stack trace just in case someone
@@ -179,7 +189,7 @@ export function parseStackTrace(
179189
}
180190
const line = +(parsed[3] || parsed[6]);
181191
const col = +(parsed[4] || parsed[7]);
182-
parsedFrames.push([name, filename, line, col]);
192+
parsedFrames.push([name, filename, line, col, 0, 0]);
183193
}
184194
return parsedFrames;
185195
}

packages/shared/ReactTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ export type ReactCallSite = [
186186
string, // file name TODO: model nested eval locations as nested arrays
187187
number, // line number
188188
number, // column number
189+
number, // enclosing line number
190+
number, // enclosing column number
189191
];
190192

191193
export type ReactStackTrace = Array<ReactCallSite>;

0 commit comments

Comments
 (0)