Skip to content

[Flight] Clarify that location field is a FunctionLocation not a CallSite #33141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
ReactAsyncInfo,
ReactTimeInfo,
ReactStackTrace,
ReactCallSite,
ReactFunctionLocation,
ReactErrorInfoDev,
} from 'shared/ReactTypes';
import type {LazyComponent} from 'react/src/ReactLazy';
Expand Down Expand Up @@ -1074,7 +1074,7 @@ function loadServerReference<A: Iterable<any>, T>(
bound: null | Thenable<Array<any>>,
name?: string, // DEV-only
env?: string, // DEV-only
location?: ReactCallSite, // DEV-only
location?: ReactFunctionLocation, // DEV-only
},
parentObject: Object,
key: string,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-client/src/ReactFlightReplyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
FulfilledThenable,
RejectedThenable,
ReactCustomFormAction,
ReactCallSite,
ReactFunctionLocation,
} from 'shared/ReactTypes';
import type {LazyComponent} from 'react/src/ReactLazy';
import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
Expand Down Expand Up @@ -1248,7 +1248,7 @@ export function createBoundServerReference<A: Iterable<any>, T>(
bound: null | Thenable<Array<any>>,
name?: string, // DEV-only
env?: string, // DEV-only
location?: ReactCallSite, // DEV-only
location?: ReactFunctionLocation, // DEV-only
},
callServer: CallServerCallback,
encodeFormAction?: EncodeFormActionCallback,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ const v8FrameRegExp =
// filename:0:0
const jscSpiderMonkeyFrameRegExp = /(?:(.*)@)?(.*):(\d+):(\d+)/;

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

return [name, filename, line, col, line, col];
return [name, filename, line, col];
}

export function createServerReference<A: Iterable<any>, T>(
Expand Down
14 changes: 10 additions & 4 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import type {
ReactAsyncInfo,
ReactTimeInfo,
ReactStackTrace,
ReactCallSite,
ReactFunctionLocation,
ReactErrorInfo,
ReactErrorInfoDev,
} from 'shared/ReactTypes';
Expand Down Expand Up @@ -2089,7 +2089,7 @@ function serializeServerReference(
const bound = boundArgs === null ? null : Promise.resolve(boundArgs);
const id = getServerReferenceId(request.bundlerConfig, serverReference);

let location: null | ReactCallSite = null;
let location: null | ReactFunctionLocation = null;
if (__DEV__) {
const error = getServerReferenceLocation(
request.bundlerConfig,
Expand All @@ -2098,7 +2098,13 @@ function serializeServerReference(
if (error) {
const frames = parseStackTrace(error, 1);
if (frames.length > 0) {
location = frames[0];
const firstFrame = frames[0];
location = [
firstFrame[0],
firstFrame[1],
firstFrame[2], // The line and col of the callsite represents the
firstFrame[3], // enclosing line and col of the function.
];
}
}
}
Expand All @@ -2108,7 +2114,7 @@ function serializeServerReference(
bound: null | Promise<Array<any>>,
name?: string, // DEV-only
env?: string, // DEV-only
location?: ReactCallSite, // DEV-only
location?: ReactFunctionLocation, // DEV-only
} =
__DEV__ && location !== null
? {
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ export type ReactCallSite = [

export type ReactStackTrace = Array<ReactCallSite>;

export type ReactFunctionLocation = [
string, // function name
string, // file name TODO: model nested eval locations as nested arrays
number, // enclosing line number
number, // enclosing column number
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like it's not the enclosing of the function location but more like what enclosing means in the context of a callsite. I.e. function location.

];

export type ReactComponentInfo = {
+name: string,
+env?: string,
Expand Down
Loading