107
108
initAsyncDebugInfo();
109
110
+// Dev-only
111
+type ReactDebugInfo = Array<{+name?: string, +env?: string}>;
112
+
113
const ObjectPrototype = Object.prototype;
114
115
type JSONValue =
202
taintCleanupQueue: Array<string | bigint>,
203
onError: (error: mixed) => ?string,
204
onPostpone: (reason: string) => void,
205
+ // DEV-only
206
+ environmentName: string,
207
};
208
209
const {
256
onError: void | ((error: mixed) => ?string),
257
identifierPrefix?: string,
258
onPostpone: void | ((reason: string) => void),
259
+ environmentName: void | string,
260
): Request {
261
if (
262
ReactCurrentCache.current !== null &&
276
TaintRegistryPendingRequests.add(cleanupQueue);
277
}
278
const hints = createHints();
273
- const request: Request = {
279
+ const request: Request = ({
280
status: OPEN,
281
flushScheduled: false,
282
fatalError: null,
301
taintCleanupQueue: cleanupQueue,
302
onError: onError === undefined ? defaultErrorHandler : onError,
303
onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone,
298
- };
304
+ }: any);
305
+ if (__DEV__) {
306
+ request.environmentName =
307
+ environmentName === undefined ? 'server' : environmentName;
308
+ }
309
const rootTask = createTask(request, model, null, false, abortSet);
310
pingedTasks.push(rootTask);
311
return request;
335
request.abortableTasks,
336
);
337
338
+ if (__DEV__) {
339
+ // If this came from Flight, forward any debug info into this new row.
340
+ const debugInfo: ?ReactDebugInfo = (thenable: any)._debugInfo;
341
+ if (debugInfo) {
342
+ forwardDebugInfo(request, newTask.id, debugInfo);
343
+ }
344
+ }
345
+
346
switch (thenable.status) {
347
case 'fulfilled': {
348
// We have the resolved value, we can go ahead and schedule it for serialization.
493
_payload: thenable,
494
_init: readThenable,
495
};
496
+ if (__DEV__) {
497
+ // If this came from React, transfer the debug info.
498
+ lazyType._debugInfo = (thenable: any)._debugInfo || [];
499
+ }
500
return lazyType;
501
}
502
526
const componentName =
527
(Component: any).displayName || Component.name || '';
528
request.pendingChunks++;
507
- emitDebugChunk(request, debugID, {name: componentName});
529
+ emitDebugChunk(request, debugID, {
530
+ name: componentName,
531
+ env: request.environmentName,
532
+ });
533
}
534
}
535
577
task: Task,
578
children: $ReadOnlyArray<ReactClientValue>,
579
): ReactJSONValue {
580
+ if (__DEV__) {
581
+ const debugInfo: ?ReactDebugInfo = (children: any)._debugInfo;
582
+ if (debugInfo) {
583
+ // If this came from Flight, forward any debug info into this new row.
584
+ if (debugID === null) {
585
+ // We don't have a chunk to assign debug info. We need to outline this
586
+ // component to assign it an ID.
587
+ return outlineTask(request, task);
588
+ } else {
589
+ // Forward any debug info we have the first time we see it.
590
+ // We do this after init so that we have received all the debug info
591
+ // from the server by the time we emit it.
592
+ forwardDebugInfo(request, debugID, debugInfo);
593
+ }
594
+ }
595
+ }
596
if (!enableServerComponentKeys) {
597
return children;
598
}
1251
}
1252
1253
const element: React$Element<any> = (value: any);
1254
+
1255
+ if (__DEV__) {
1256
+ const debugInfo: ?ReactDebugInfo = (value: any)._debugInfo;
1257
+ if (debugInfo) {
1258
+ // If this came from Flight, forward any debug info into this new row.
1259
+ if (debugID === null) {
1260
+ // We don't have a chunk to assign debug info. We need to outline this
1261
+ // component to assign it an ID.
1262
+ return outlineTask(request, task);
1263
+ } else {
1264
+ // Forward any debug info we have the first time we see it.
1265
+ forwardDebugInfo(request, debugID, debugInfo);
1266
+ }
1267
+ }
1268
+ }
1269
+
1270
// Attempt to render the Server Component.
1271
return renderElement(
1272
request,
1279
);
1280
}
1281
case REACT_LAZY_TYPE: {
1225
- const payload = (value: any)._payload;
1226
- const init = (value: any)._init;
1282
+ // Reset the task's thenable state before continuing. If there was one, it was
1283
+ // from suspending the lazy before.
1284
+ task.thenableState = null;
1285
+
1286
+ const lazy: LazyComponent<any, any> = (value: any);
1287
+ const payload = lazy._payload;
1288
+ const init = lazy._init;
1289
const resolvedModel = init(payload);
1290
+ if (__DEV__) {
1291
+ const debugInfo: ?ReactDebugInfo = lazy._debugInfo;
1292
+ if (debugInfo) {
1293
+ // If this came from Flight, forward any debug info into this new row.
1294
+ if (debugID === null) {
1295
+ // We don't have a chunk to assign debug info. We need to outline this
1296
+ // component to assign it an ID.
1297
+ return outlineTask(request, task);
1298
+ } else {
1299
+ // Forward any debug info we have the first time we see it.
1300
+ // We do this after init so that we have received all the debug info
1301
+ // from the server by the time we emit it.
1302
+ forwardDebugInfo(request, debugID, debugInfo);
1303
+ }
1304
+ }
1305
+ }
1306
return renderModelDestructive(
1307
request,
1308
task,
1731
function emitDebugChunk(
1732
request: Request,
1733
id: number,
1656
- debugInfo: {name: string},
1734
+ debugInfo: {+name?: string, +env?: string},
1735
): void {
1736
if (!__DEV__) {
1737
// These errors should never make it into a build so we don't need to encode them in codes.json
1747
request.completedRegularChunks.push(processedChunk);
1748
}
1749
1750
+function forwardDebugInfo(
1751
+ request: Request,
1752
+ id: number,
1753
+ debugInfo: ReactDebugInfo,
1754
+) {
1755
+ for (let i = 0; i < debugInfo.length; i++) {
1756
+ request.pendingChunks++;
1757
+ emitDebugChunk(request, id, debugInfo[i]);
1758
+ }
1759
+}
1760
+
1761
const emptyRoot = {};
1762
1763
function retryTask(request: Request, task: Task): void {