From fbd7352d78a4c40855355efb1a2cb3234dce78ca Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Wed, 7 May 2025 12:49:14 -0400 Subject: [PATCH] Clarify that location field is a FunctionLocation not a CallSite --- packages/react-client/src/ReactFlightClient.js | 4 ++-- .../react-client/src/ReactFlightReplyClient.js | 8 ++++---- packages/react-server/src/ReactFlightServer.js | 14 ++++++++++---- packages/shared/ReactTypes.js | 7 +++++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/react-client/src/ReactFlightClient.js b/packages/react-client/src/ReactFlightClient.js index fbf195ba7b65a..7d6bbd5c1fbb0 100644 --- a/packages/react-client/src/ReactFlightClient.js +++ b/packages/react-client/src/ReactFlightClient.js @@ -15,7 +15,7 @@ import type { ReactAsyncInfo, ReactTimeInfo, ReactStackTrace, - ReactCallSite, + ReactFunctionLocation, ReactErrorInfoDev, } from 'shared/ReactTypes'; import type {LazyComponent} from 'react/src/ReactLazy'; @@ -1074,7 +1074,7 @@ function loadServerReference, T>( bound: null | Thenable>, name?: string, // DEV-only env?: string, // DEV-only - location?: ReactCallSite, // DEV-only + location?: ReactFunctionLocation, // DEV-only }, parentObject: Object, key: string, diff --git a/packages/react-client/src/ReactFlightReplyClient.js b/packages/react-client/src/ReactFlightReplyClient.js index cf21d6e9adf13..6a0a37b787d34 100644 --- a/packages/react-client/src/ReactFlightReplyClient.js +++ b/packages/react-client/src/ReactFlightReplyClient.js @@ -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'; @@ -1248,7 +1248,7 @@ export function createBoundServerReference, T>( bound: null | Thenable>, name?: string, // DEV-only env?: string, // DEV-only - location?: ReactCallSite, // DEV-only + location?: ReactFunctionLocation, // DEV-only }, callServer: CallServerCallback, encodeFormAction?: EncodeFormActionCallback, @@ -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 @@ -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, T>( diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index dd946280f9395..ed6d9c443b7bc 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -62,7 +62,7 @@ import type { ReactAsyncInfo, ReactTimeInfo, ReactStackTrace, - ReactCallSite, + ReactFunctionLocation, ReactErrorInfo, ReactErrorInfoDev, } from 'shared/ReactTypes'; @@ -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, @@ -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. + ]; } } } @@ -2108,7 +2114,7 @@ function serializeServerReference( bound: null | Promise>, name?: string, // DEV-only env?: string, // DEV-only - location?: ReactCallSite, // DEV-only + location?: ReactFunctionLocation, // DEV-only } = __DEV__ && location !== null ? { diff --git a/packages/shared/ReactTypes.js b/packages/shared/ReactTypes.js index 2172c92bfc90a..4c8ca77bb160b 100644 --- a/packages/shared/ReactTypes.js +++ b/packages/shared/ReactTypes.js @@ -192,6 +192,13 @@ export type ReactCallSite = [ export type ReactStackTrace = Array; +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 +]; + export type ReactComponentInfo = { +name: string, +env?: string,