Skip to content
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

Update ReactDebugInfo types to declare timing info separately #31714

Merged
merged 3 commits into from
Dec 10, 2024
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
49 changes: 36 additions & 13 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import type {
Thenable,
ReactDebugInfo,
ReactComponentInfo,
ReactEnvironmentInfo,
ReactAsyncInfo,
ReactTimeInfo,
ReactStackTrace,
ReactCallSite,
} from 'shared/ReactTypes';
Expand Down Expand Up @@ -2460,7 +2462,6 @@ function initializeFakeStack(
const stack = debugInfo.stack;
const env = debugInfo.env == null ? '' : debugInfo.env;
// $FlowFixMe[cannot-write]
// $FlowFixMe[prop-missing]
debugInfo.debugStack = createFakeJSXCallStackInDEV(response, stack, env);
}
if (debugInfo.owner != null) {
Expand All @@ -2472,7 +2473,11 @@ function initializeFakeStack(
function resolveDebugInfo(
response: Response,
id: number,
debugInfo: ReactComponentInfo | ReactAsyncInfo,
debugInfo:
| ReactComponentInfo
| ReactEnvironmentInfo
| ReactAsyncInfo
| ReactTimeInfo,
): void {
if (!__DEV__) {
// These errors should never make it into a build so we don't need to encode them in codes.json
Expand All @@ -2486,16 +2491,26 @@ function resolveDebugInfo(
// to initialize it when we need it, we might be inside user code.
const env =
debugInfo.env === undefined ? response._rootEnvironmentName : debugInfo.env;
initializeFakeTask(response, debugInfo, env);
if (debugInfo.stack !== undefined) {
const componentInfoOrAsyncInfo: ReactComponentInfo | ReactAsyncInfo =
// $FlowFixMe[incompatible-type]
debugInfo;
initializeFakeTask(response, componentInfoOrAsyncInfo, env);
}
if (debugInfo.owner === null && response._debugRootOwner != null) {
// $FlowFixMe
debugInfo.owner = response._debugRootOwner;
// $FlowFixMe[prop-missing] By narrowing `owner` to `null`, we narrowed `debugInfo` to `ReactComponentInfo`
const componentInfo: ReactComponentInfo = debugInfo;
// $FlowFixMe[cannot-write]
componentInfo.owner = response._debugRootOwner;
// We override the stack if we override the owner since the stack where the root JSX
// was created on the server isn't very useful but where the request was made is.
// $FlowFixMe
debugInfo.debugStack = response._debugRootStack;
} else {
initializeFakeStack(response, debugInfo);
// $FlowFixMe[cannot-write]
componentInfo.debugStack = response._debugRootStack;
} else if (debugInfo.stack !== undefined) {
const componentInfoOrAsyncInfo: ReactComponentInfo | ReactAsyncInfo =
// $FlowFixMe[incompatible-type]
debugInfo;
initializeFakeStack(response, componentInfoOrAsyncInfo);
}

const chunk = getChunk(response, id);
Expand Down Expand Up @@ -2779,11 +2794,19 @@ function processFullStringRow(
}
case 68 /* "D" */: {
if (__DEV__) {
const chunk: ResolvedModelChunk<ReactComponentInfo | ReactAsyncInfo> =
createResolvedModelChunk(response, row);
const chunk: ResolvedModelChunk<
| ReactComponentInfo
| ReactEnvironmentInfo
| ReactAsyncInfo
| ReactTimeInfo,
> = createResolvedModelChunk(response, row);
initializeModelChunk(chunk);
const initializedChunk: SomeChunk<ReactComponentInfo | ReactAsyncInfo> =
chunk;
const initializedChunk: SomeChunk<
| ReactComponentInfo
| ReactEnvironmentInfo
| ReactAsyncInfo
| ReactTimeInfo,
> = chunk;
if (initializedChunk.status === INITIALIZED) {
resolveDebugInfo(response, id, initializedChunk.value);
} else {
Expand Down
8 changes: 7 additions & 1 deletion packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ import type {
RejectedThenable,
ReactDebugInfo,
ReactComponentInfo,
ReactEnvironmentInfo,
ReactAsyncInfo,
ReactTimeInfo,
ReactStackTrace,
ReactCallSite,
} from 'shared/ReactTypes';
Expand Down Expand Up @@ -3244,7 +3246,11 @@ function emitModelChunk(request: Request, id: number, json: string): void {
function emitDebugChunk(
request: Request,
id: number,
debugInfo: ReactComponentInfo | ReactAsyncInfo,
debugInfo:
| ReactComponentInfo
| ReactAsyncInfo
| ReactEnvironmentInfo
| ReactTimeInfo,
): void {
if (!__DEV__) {
// These errors should never make it into a build so we don't need to encode them in codes.json
Expand Down
20 changes: 16 additions & 4 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export type ReactCallSite = [
export type ReactStackTrace = Array<ReactCallSite>;

export type ReactComponentInfo = {
+name?: string,
+name: string,
+env?: string,
+key?: null | string,
+owner?: null | ReactComponentInfo,
Expand All @@ -199,10 +199,22 @@ export type ReactComponentInfo = {
+debugTask?: null | ConsoleTask,
};

export type ReactEnvironmentInfo = {
+env: string,
};

export type ReactAsyncInfo = {
+started?: number,
+completed?: number,
+type: string,
// Stashed Data for the Specific Execution Environment. Not part of the transport protocol
+debugStack?: null | Error,
+debugTask?: null | ConsoleTask,
+stack?: null | ReactStackTrace,
};

export type ReactDebugInfo = Array<ReactComponentInfo | ReactAsyncInfo>;
export type ReactTimeInfo = {
+time: number, // performance.now
};

export type ReactDebugInfo = Array<
ReactComponentInfo | ReactEnvironmentInfo | ReactAsyncInfo | ReactTimeInfo,
>;
Loading