Skip to content

Commit 0e43943

Browse files
committed
Include env in ReactAsyncInfo and ReactIOInfo
This lets us keep track of which environment this was fetched and awaited. Currently the IO and await is in the same environment. Once we support forwarding information from a Promise fetched from another environment, the await can end up being in a different environment.
1 parent 45da4e0 commit 0e43943

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,9 +2758,7 @@ function resolveConsoleEntry(
27582758

27592759
function initializeIOInfo(response: Response, ioInfo: ReactIOInfo): void {
27602760
const env =
2761-
// TODO: Pass env through I/O info.
2762-
// ioInfo.env !== undefined ? ioInfo.env :
2763-
response._rootEnvironmentName;
2761+
ioInfo.env === undefined ? response._rootEnvironmentName : ioInfo.env;
27642762
if (ioInfo.stack !== undefined) {
27652763
initializeFakeTask(response, ioInfo, env);
27662764
initializeFakeStack(response, ioInfo);

packages/react-server/src/ReactFlightServer.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,10 +1930,14 @@ function visitAsyncNode(
19301930
}
19311931
// Outline the IO node.
19321932
serializeIONode(request, ioNode);
1933+
// We log the environment at the time when the last promise pigned ping which may
1934+
// be later than what the environment was when we actually started awaiting.
1935+
const env = (0, request.environmentName)();
19331936
// Then emit a reference to us awaiting it in the current task.
19341937
request.pendingChunks++;
19351938
emitDebugChunk(request, task.id, {
19361939
awaited: ((ioNode: any): ReactIOInfo), // This is deduped by this reference.
1940+
env: env,
19371941
owner: node.owner,
19381942
stack: stack,
19391943
});
@@ -1969,8 +1973,12 @@ function emitAsyncSequence(
19691973
}
19701974
serializeIONode(request, awaitedNode);
19711975
request.pendingChunks++;
1976+
// We log the environment at the time when we ping which may be later than what the
1977+
// environment was when we actually started awaiting.
1978+
const env = (0, request.environmentName)();
19721979
emitDebugChunk(request, task.id, {
19731980
awaited: ((awaitedNode: any): ReactIOInfo), // This is deduped by this reference.
1981+
env: env,
19741982
});
19751983
}
19761984
}
@@ -3524,6 +3532,7 @@ function emitIOInfoChunk(
35243532
name: string,
35253533
start: number,
35263534
end: number,
3535+
env: ?string,
35273536
owner: ?ReactComponentInfo,
35283537
stack: ?ReactStackTrace,
35293538
): void {
@@ -3563,6 +3572,10 @@ function emitIOInfoChunk(
35633572
start: relativeStartTimestamp,
35643573
end: relativeEndTimestamp,
35653574
};
3575+
if (env != null) {
3576+
// $FlowFixMe[cannot-write]
3577+
debugIOInfo.env = env;
3578+
}
35663579
if (stack != null) {
35673580
// $FlowFixMe[cannot-write]
35683581
debugIOInfo.stack = stack;
@@ -3597,6 +3610,7 @@ function outlineIOInfo(request: Request, ioInfo: ReactIOInfo): void {
35973610
ioInfo.name,
35983611
ioInfo.start,
35993612
ioInfo.end,
3613+
ioInfo.env,
36003614
owner,
36013615
ioInfo.stack,
36023616
);
@@ -3633,9 +3647,22 @@ function serializeIONode(
36333647
outlineComponentInfo(request, owner);
36343648
}
36353649

3650+
// We log the environment at the time when we serialize the I/O node.
3651+
// The environment name may have changed from when the I/O was actually started.
3652+
const env = (0, request.environmentName)();
3653+
36363654
request.pendingChunks++;
36373655
const id = request.nextChunkId++;
3638-
emitIOInfoChunk(request, id, name, ioNode.start, ioNode.end, owner, stack);
3656+
emitIOInfoChunk(
3657+
request,
3658+
id,
3659+
name,
3660+
ioNode.start,
3661+
ioNode.end,
3662+
env,
3663+
owner,
3664+
stack,
3665+
);
36393666
const ref = serializeByValueID(id);
36403667
request.writtenObjects.set(ioNode, ref);
36413668
return ref;
@@ -4161,6 +4188,7 @@ function forwardDebugInfo(
41614188
const debugAsyncInfo: Omit<ReactAsyncInfo, 'debugTask' | 'debugStack'> =
41624189
{
41634190
awaited: ioInfo,
4191+
env: debugInfo[i].env,
41644192
owner: debugInfo[i].owner,
41654193
stack: debugInfo[i].stack,
41664194
};

packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ describe('ReactFlightAsyncDebugInfo', () => {
173173
{
174174
"awaited": {
175175
"end": 0,
176+
"env": "Server",
176177
"name": "delay",
177178
"owner": {
178179
"env": "Server",
@@ -219,6 +220,7 @@ describe('ReactFlightAsyncDebugInfo', () => {
219220
],
220221
"start": 0,
221222
},
223+
"env": "Server",
222224
"owner": {
223225
"env": "Server",
224226
"key": null,
@@ -258,6 +260,7 @@ describe('ReactFlightAsyncDebugInfo', () => {
258260
{
259261
"awaited": {
260262
"end": 0,
263+
"env": "Server",
261264
"name": "delay",
262265
"owner": {
263266
"env": "Server",
@@ -304,6 +307,7 @@ describe('ReactFlightAsyncDebugInfo', () => {
304307
],
305308
"start": 0,
306309
},
310+
"env": "Server",
307311
"owner": {
308312
"env": "Server",
309313
"key": null,
@@ -394,16 +398,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
394398
[
395399
"Object.<anonymous>",
396400
"/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
397-
364,
401+
368,
398402
109,
399-
351,
403+
355,
400404
67,
401405
],
402406
],
403407
},
404408
{
405409
"awaited": {
406410
"end": 0,
411+
"env": "Server",
407412
"name": "setTimeout",
408413
"owner": {
409414
"env": "Server",
@@ -415,9 +420,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
415420
[
416421
"Object.<anonymous>",
417422
"/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
418-
364,
423+
368,
419424
109,
420-
351,
425+
355,
421426
67,
422427
],
423428
],
@@ -426,14 +431,15 @@ describe('ReactFlightAsyncDebugInfo', () => {
426431
[
427432
"Component",
428433
"/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
429-
354,
434+
358,
430435
7,
431-
352,
436+
356,
432437
5,
433438
],
434439
],
435440
"start": 0,
436441
},
442+
"env": "Server",
437443
},
438444
{
439445
"time": 0,

packages/shared/ReactTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export type ReactIOInfo = {
234234
+name: string, // the name of the async function being called (e.g. "fetch")
235235
+start: number, // the start time
236236
+end: number, // the end time (this might be different from the time the await was unblocked)
237+
+env?: string, // the environment where this I/O was spawned.
237238
+owner?: null | ReactComponentInfo,
238239
+stack?: null | ReactStackTrace,
239240
// Stashed Data for the Specific Execution Environment. Not part of the transport protocol
@@ -243,6 +244,7 @@ export type ReactIOInfo = {
243244

244245
export type ReactAsyncInfo = {
245246
+awaited: ReactIOInfo,
247+
+env?: string, // the environment where this was awaited. This might not be the same as where it was spawned.
246248
+owner?: null | ReactComponentInfo,
247249
+stack?: null | ReactStackTrace,
248250
// Stashed Data for the Specific Execution Environment. Not part of the transport protocol

0 commit comments

Comments
 (0)