Skip to content

Commit

Permalink
Serialize Server Reference Debug Meta Data
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Aug 17, 2024
1 parent 91a2e0c commit 44839f4
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import type {
ReactComponentInfo,
ReactAsyncInfo,
ReactStackTrace,
ReactCallSite,
} from 'shared/ReactTypes';
import type {ReactElement} from 'shared/ReactElementType';
import type {LazyComponent} from 'react/src/ReactLazy';
Expand All @@ -72,6 +73,7 @@ import {
resolveClientReferenceMetadata,
getServerReferenceId,
getServerReferenceBoundArguments,
getServerReferenceLocation,
getClientReferenceKey,
isClientReference,
isServerReference,
Expand Down Expand Up @@ -1955,17 +1957,47 @@ function serializeServerReference(
return serializeServerReferenceID(existingId);
}

const bound: null | Array<any> = getServerReferenceBoundArguments(
const boundArgs: null | Array<any> = getServerReferenceBoundArguments(
request.bundlerConfig,
serverReference,
);
const bound = boundArgs === null ? null : Promise.resolve(boundArgs);
const id = getServerReferenceId(request.bundlerConfig, serverReference);

let location: null | ReactCallSite = null;
if (__DEV__) {
const error = getServerReferenceLocation(
request.bundlerConfig,
serverReference,
);
if (error) {
const frames = parseStackTrace(error, 1);
if (frames.length > 0) {
location = frames[0];
}
}
}

const serverReferenceMetadata: {
id: ServerReferenceId,
bound: null | Promise<Array<any>>,
} = {
id: getServerReferenceId(request.bundlerConfig, serverReference),
bound: bound ? Promise.resolve(bound) : null,
};
name?: string, // DEV-only
env?: string, // DEV-only
location?: ReactCallSite, // DEV-only
} =
__DEV__ && location !== null
? {
id,
bound,
name:
typeof serverReference === 'function' ? serverReference.name : '',
env: (0, request.environmentName)(),
location,
}
: {
id,
bound,
};
const metadataId = outlineModel(request, serverReferenceMetadata);
writtenServerReferences.set(serverReference, metadataId);
return serializeServerReferenceID(metadataId);
Expand Down

0 comments on commit 44839f4

Please sign in to comment.