MCPcopy Index your code
hub / github.com/react/react / serializeDebugClientReference

Function serializeDebugClientReference

packages/react-server/src/ReactFlightServer.js:2802–2849  ·  view source on GitHub ↗
(
  request: Request,
  parent:
    | {+[propertyName: string | number]: ReactClientValue}
    | $ReadOnlyArray<ReactClientValue>,
  parentPropertyName: string,
  clientReference: ClientReference<any>,
)

Source from the content-addressed store, hash-verified

2800}
2801
2802function serializeDebugClientReference(
2803 request: Request,
2804 parent:
2805 | {+[propertyName: string | number]: ReactClientValue}
2806 | $ReadOnlyArray<ReactClientValue>,
2807 parentPropertyName: string,
2808 clientReference: ClientReference<any>,
2809): string {
2810 // Like serializeDebugClientReference but it doesn't dedupe in the regular set
2811 // and it writes to completedDebugChunk instead of imports.
2812 const clientReferenceKey: ClientReferenceKey =
2813 getClientReferenceKey(clientReference);
2814 const writtenClientReferences = request.writtenClientReferences;
2815 const existingId = writtenClientReferences.get(clientReferenceKey);
2816 if (existingId !== undefined) {
2817 if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
2818 // If we're encoding the "type" of an element, we can refer
2819 // to that by a lazy reference instead of directly since React
2820 // knows how to deal with lazy values. This lets us suspend
2821 // on this component rather than its parent until the code has
2822 // loaded.
2823 return serializeLazyID(existingId);
2824 }
2825 return serializeByValueID(existingId);
2826 }
2827 try {
2828 const clientReferenceMetadata: ClientReferenceMetadata =
2829 resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
2830 request.pendingDebugChunks++;
2831 const importId = request.nextChunkId++;
2832 emitImportChunk(request, importId, clientReferenceMetadata, true);
2833 if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
2834 // If we're encoding the "type" of an element, we can refer
2835 // to that by a lazy reference instead of directly since React
2836 // knows how to deal with lazy values. This lets us suspend
2837 // on this component rather than its parent until the code has
2838 // loaded.
2839 return serializeLazyID(importId);
2840 }
2841 return serializeByValueID(importId);
2842 } catch (x) {
2843 request.pendingDebugChunks++;
2844 const errorId = request.nextChunkId++;
2845 const digest = logRecoverableError(request, x, null);
2846 emitErrorChunk(request, errorId, digest, x, true, null);
2847 return serializeByValueID(errorId);
2848 }
2849}
2850
2851function outlineModel(request: Request, value: ReactClientValue): number {
2852 return outlineModelWithFormatContext(

Callers 1

renderDebugModelFunction · 0.85

Calls 8

getClientReferenceKeyFunction · 0.90
serializeLazyIDFunction · 0.85
emitImportChunkFunction · 0.85
emitErrorChunkFunction · 0.85
serializeByValueIDFunction · 0.70
logRecoverableErrorFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected