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

Function processReply

packages/react-client/src/ReactFlightReplyClient.js:180–903  ·  packages/react-client/src/ReactFlightReplyClient.js::processReply
(
  root: ReactServerValue,
  formFieldPrefix: string,
  temporaryReferences: void | TemporaryReferenceSet,
  resolve: (string | FormData) => void,
  reject: (error: mixed) => void,
)

Source from the content-addressed store, hash-verified

178interface Reference {}
179
180export function processReply(
181 root: ReactServerValue,
182 formFieldPrefix: string,
183 temporaryReferences: void | TemporaryReferenceSet,
184 resolve: (string | FormData) => void,
185 reject: (error: mixed) => void,
186): (reason: mixed) => void {
187 let nextPartId = 1;
188 let pendingParts = 0;
189 let formData: null | FormData = null;
190 const writtenObjects: WeakMap<Reference, string> = new WeakMap();
191 let modelRoot: null | ReactServerValue = root;
192
193 function serializeTypedArray(
194 tag: string,
195 typedArray: $ArrayBufferView,
196 ): string {
197 const blob = new Blob([
198 class="cm">// We should be able to pass the buffer straight through but Node < 18 treat
199 class="cm">// multi-byte array blobs differently so we first convert it to single-byte.
200 new Uint8Array(
201 typedArray.buffer,
202 typedArray.byteOffset,
203 typedArray.byteLength,
204 ),
205 ]);
206 const blobId = nextPartId++;
207 if (formData === null) {
208 formData = new FormData();
209 }
210 formData.append(formFieldPrefix + blobId, blob);
211 return class="st">'$' + tag + blobId.toString(16);
212 }
213
214 function serializeBinaryReader(reader: any): string {
215 if (formData === null) {
216 class="cm">// Upgrade to use FormData to allow us to stream this value.
217 formData = new FormData();
218 }
219 const data = formData;
220
221 pendingParts++;
222 const streamId = nextPartId++;
223
224 const buffer = [];
225
226 function progress(entry: {done: boolean, value: ReactServerValue, ...}) {
227 if (entry.done) {
228 const blobId = nextPartId++;
229 data.append(formFieldPrefix + blobId, new Blob(buffer));
230 data.append(
231 formFieldPrefix + streamId,
232 class="st">'"$o' + blobId.toString(16) + class="st">'"',
233 );
234 data.append(formFieldPrefix + streamId, class="st">'C'); class="cm">// Close signal
235 pendingParts--;
236 if (pendingParts === 0) {
237 resolve(data);

Callers 9

encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeReplyFunction · 0.90
encodeFormDataFunction · 0.85

Calls 3

serializeModelFunction · 0.85
setMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected