MCPcopy
hub / github.com/facebook/react / serializeServerReference

Function serializeServerReference

packages/react-server/src/ReactFlightServer.js:2885–2945  ·  view source on GitHub ↗
(
  request: Request,
  serverReference: ServerReference<any>,
)

Source from the content-addressed store, hash-verified

2883}
2884
2885function serializeServerReference(
2886 request: Request,
2887 serverReference: ServerReference<any>,
2888): string {
2889 const writtenServerReferences = request.writtenServerReferences;
2890 const existingId = writtenServerReferences.get(serverReference);
2891 if (existingId !== undefined) {
2892 return serializeServerReferenceID(existingId);
2893 }
2894
2895 const boundArgs: null | Array<any> = getServerReferenceBoundArguments(
2896 request.bundlerConfig,
2897 serverReference,
2898 );
2899 const bound = boundArgs === null ? null : Promise.resolve(boundArgs);
2900 const id = getServerReferenceId(request.bundlerConfig, serverReference);
2901
2902 let location: null | ReactFunctionLocation = null;
2903 if (__DEV__) {
2904 const error = getServerReferenceLocation(
2905 request.bundlerConfig,
2906 serverReference,
2907 );
2908 if (error) {
2909 const frames = parseStackTrace(error, 1);
2910 if (frames.length > 0) {
2911 const firstFrame = frames[0];
2912 location = [
2913 firstFrame[0],
2914 firstFrame[1],
2915 firstFrame[2], // The line and col of the callsite represents the
2916 firstFrame[3], // enclosing line and col of the function.
2917 ];
2918 }
2919 }
2920 }
2921
2922 const serverReferenceMetadata: {
2923 id: ServerReferenceId,
2924 bound: null | Promise<Array<any>>,
2925 name?: string, // DEV-only
2926 env?: string, // DEV-only
2927 location?: ReactFunctionLocation, // DEV-only
2928 } =
2929 __DEV__ && location !== null
2930 ? {
2931 id,
2932 bound,
2933 name:
2934 typeof serverReference === 'function' ? serverReference.name : '',
2935 env: (0, request.environmentName)(),
2936 location,
2937 }
2938 : {
2939 id,
2940 bound,
2941 };
2942 const metadataId = outlineModel(request, serverReferenceMetadata);

Callers 1

renderModelDestructiveFunction · 0.85

Calls 8

getServerReferenceIdFunction · 0.90
outlineModelFunction · 0.85
setMethod · 0.80
parseStackTraceFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected