Skip to content

Commit a437c99

Browse files
authored
[Flight] Clarify that location field is a FunctionLocation not a CallSite (facebook#33141)
Follow up to facebook#33136. This clarifies in the types where the conversion happens from a CallSite which we use to simulate getting the enclosing line/col to a FunctionLocation which doesn't represent a CallSite but actually just the function which only has an enclosing line/col.
1 parent 4206fe4 commit a437c99

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
ReactAsyncInfo,
1616
ReactTimeInfo,
1717
ReactStackTrace,
18-
ReactCallSite,
18+
ReactFunctionLocation,
1919
ReactErrorInfoDev,
2020
} from 'shared/ReactTypes';
2121
import type {LazyComponent} from 'react/src/ReactLazy';
@@ -1074,7 +1074,7 @@ function loadServerReference<A: Iterable<any>, T>(
10741074
bound: null | Thenable<Array<any>>,
10751075
name?: string, // DEV-only
10761076
env?: string, // DEV-only
1077-
location?: ReactCallSite, // DEV-only
1077+
location?: ReactFunctionLocation, // DEV-only
10781078
},
10791079
parentObject: Object,
10801080
key: string,

packages/react-client/src/ReactFlightReplyClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
FulfilledThenable,
1414
RejectedThenable,
1515
ReactCustomFormAction,
16-
ReactCallSite,
16+
ReactFunctionLocation,
1717
} from 'shared/ReactTypes';
1818
import type {LazyComponent} from 'react/src/ReactLazy';
1919
import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
@@ -1248,7 +1248,7 @@ export function createBoundServerReference<A: Iterable<any>, T>(
12481248
bound: null | Thenable<Array<any>>,
12491249
name?: string, // DEV-only
12501250
env?: string, // DEV-only
1251-
location?: ReactCallSite, // DEV-only
1251+
location?: ReactFunctionLocation, // DEV-only
12521252
},
12531253
callServer: CallServerCallback,
12541254
encodeFormAction?: EncodeFormActionCallback,
@@ -1309,7 +1309,7 @@ const v8FrameRegExp =
13091309
// filename:0:0
13101310
const jscSpiderMonkeyFrameRegExp = /(?:(.*)@)?(.*):(\d+):(\d+)/;
13111311

1312-
function parseStackLocation(error: Error): null | ReactCallSite {
1312+
function parseStackLocation(error: Error): null | ReactFunctionLocation {
13131313
// This parsing is special in that we know that the calling function will always
13141314
// be a module that initializes the server action. We also need this part to work
13151315
// cross-browser so not worth a Config. It's DEV only so not super code size
@@ -1354,7 +1354,7 @@ function parseStackLocation(error: Error): null | ReactCallSite {
13541354
const line = +(parsed[3] || parsed[6]);
13551355
const col = +(parsed[4] || parsed[7]);
13561356

1357-
return [name, filename, line, col, line, col];
1357+
return [name, filename, line, col];
13581358
}
13591359

13601360
export function createServerReference<A: Iterable<any>, T>(

packages/react-server/src/ReactFlightServer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import type {
6262
ReactAsyncInfo,
6363
ReactTimeInfo,
6464
ReactStackTrace,
65-
ReactCallSite,
65+
ReactFunctionLocation,
6666
ReactErrorInfo,
6767
ReactErrorInfoDev,
6868
} from 'shared/ReactTypes';
@@ -2089,7 +2089,7 @@ function serializeServerReference(
20892089
const bound = boundArgs === null ? null : Promise.resolve(boundArgs);
20902090
const id = getServerReferenceId(request.bundlerConfig, serverReference);
20912091

2092-
let location: null | ReactCallSite = null;
2092+
let location: null | ReactFunctionLocation = null;
20932093
if (__DEV__) {
20942094
const error = getServerReferenceLocation(
20952095
request.bundlerConfig,
@@ -2098,7 +2098,13 @@ function serializeServerReference(
20982098
if (error) {
20992099
const frames = parseStackTrace(error, 1);
21002100
if (frames.length > 0) {
2101-
location = frames[0];
2101+
const firstFrame = frames[0];
2102+
location = [
2103+
firstFrame[0],
2104+
firstFrame[1],
2105+
firstFrame[2], // The line and col of the callsite represents the
2106+
firstFrame[3], // enclosing line and col of the function.
2107+
];
21022108
}
21032109
}
21042110
}
@@ -2108,7 +2114,7 @@ function serializeServerReference(
21082114
bound: null | Promise<Array<any>>,
21092115
name?: string, // DEV-only
21102116
env?: string, // DEV-only
2111-
location?: ReactCallSite, // DEV-only
2117+
location?: ReactFunctionLocation, // DEV-only
21122118
} =
21132119
__DEV__ && location !== null
21142120
? {

packages/shared/ReactTypes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ export type ReactCallSite = [
192192

193193
export type ReactStackTrace = Array<ReactCallSite>;
194194

195+
export type ReactFunctionLocation = [
196+
string, // function name
197+
string, // file name TODO: model nested eval locations as nested arrays
198+
number, // enclosing line number
199+
number, // enclosing column number
200+
];
201+
195202
export type ReactComponentInfo = {
196203
+name: string,
197204
+env?: string,

0 commit comments

Comments
 (0)