Skip to content

Commit c4aeba9

Browse files
committed
[Flight] Transfer Debug Info in Server-to-Server Flight Requests (#28275)
A Flight Server can be a consumer of a stream from another Server. In this case the meta data is attached to debugInfo properties on lazy, Promises, Arrays or Elements that might in turn get forwarded to the next stream. In this case we want to forward this debug information to the client in the stream. I also added a DEV only `environmentName` option to the Flight Server. This lets you name the server that is producing the debug info so that you can trace the origin of where that component is executing. This defaults to `"server"`. DevTools could use this for badges or different colors. DiffTrain build for [629541b](629541b)
1 parent 9adade5 commit c4aeba9

5 files changed

+101
-11
lines changed

compiled/facebook-www/REVISION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
35b2c28178bf4f79898d11dce0bc2a7ce675f670
1+
629541bcc09fc7c0cc5c257541d084ee27457512

compiled/facebook-www/ReactDOMTesting-prod.modern.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17116,7 +17116,7 @@ Internals.Events = [
1711617116
var devToolsConfig$jscomp$inline_1786 = {
1711717117
findFiberByHostInstance: getClosestInstanceFromNode,
1711817118
bundleType: 0,
17119-
version: "18.3.0-www-modern-6880028a",
17119+
version: "18.3.0-www-modern-9c7ddd0b",
1712017120
rendererPackageName: "react-dom"
1712117121
};
1712217122
var internals$jscomp$inline_2162 = {
@@ -17147,7 +17147,7 @@ var internals$jscomp$inline_2162 = {
1714717147
scheduleRoot: null,
1714817148
setRefreshHandler: null,
1714917149
getCurrentFiber: null,
17150-
reconcilerVersion: "18.3.0-www-modern-6880028a"
17150+
reconcilerVersion: "18.3.0-www-modern-9c7ddd0b"
1715117151
};
1715217152
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1715317153
var hook$jscomp$inline_2163 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17575,4 +17575,4 @@ exports.useFormStatus = function () {
1757517575
return ReactCurrentDispatcher$2.current.useHostTransitionStatus();
1757617576
throw Error(formatProdErrorMessage(248));
1757717577
};
17578-
exports.version = "18.3.0-www-modern-6880028a";
17578+
exports.version = "18.3.0-www-modern-9c7ddd0b";

compiled/facebook-www/ReactFlightDOMServer-dev.modern.js

+95-6
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@ if (__DEV__) {
11041104
bundlerConfig,
11051105
onError,
11061106
identifierPrefix,
1107-
onPostpone
1107+
onPostpone,
1108+
environmentName
11081109
) {
11091110
if (
11101111
ReactCurrentCache.current !== null &&
@@ -1149,6 +1150,12 @@ if (__DEV__) {
11491150
onPostpone:
11501151
onPostpone === undefined ? defaultPostponeHandler : onPostpone
11511152
};
1153+
1154+
{
1155+
request.environmentName =
1156+
environmentName === undefined ? "server" : environmentName;
1157+
}
1158+
11521159
var rootTask = createTask(request, model, null, false, abortSet);
11531160
pingedTasks.push(rootTask);
11541161
return request;
@@ -1169,6 +1176,15 @@ if (__DEV__) {
11691176
request.abortableTasks
11701177
);
11711178

1179+
{
1180+
// If this came from Flight, forward any debug info into this new row.
1181+
var debugInfo = thenable._debugInfo;
1182+
1183+
if (debugInfo) {
1184+
forwardDebugInfo(request, newTask.id, debugInfo);
1185+
}
1186+
}
1187+
11721188
switch (thenable.status) {
11731189
case "fulfilled": {
11741190
// We have the resolved value, we can go ahead and schedule it for serialization.
@@ -1308,6 +1324,12 @@ if (__DEV__) {
13081324
_payload: thenable,
13091325
_init: readThenable
13101326
};
1327+
1328+
{
1329+
// If this came from React, transfer the debug info.
1330+
lazyType._debugInfo = thenable._debugInfo || [];
1331+
}
1332+
13111333
return lazyType;
13121334
}
13131335

@@ -1329,7 +1351,8 @@ if (__DEV__) {
13291351
var componentName = Component.displayName || Component.name || "";
13301352
request.pendingChunks++;
13311353
emitDebugChunk(request, debugID, {
1332-
name: componentName
1354+
name: componentName,
1355+
env: request.environmentName
13331356
});
13341357
}
13351358
}
@@ -1378,6 +1401,24 @@ if (__DEV__) {
13781401
}
13791402

13801403
function renderFragment(request, task, children) {
1404+
{
1405+
var debugInfo = children._debugInfo;
1406+
1407+
if (debugInfo) {
1408+
// If this came from Flight, forward any debug info into this new row.
1409+
if (debugID === null) {
1410+
// We don't have a chunk to assign debug info. We need to outline this
1411+
// component to assign it an ID.
1412+
return outlineTask(request, task);
1413+
} else {
1414+
// Forward any debug info we have the first time we see it.
1415+
// We do this after init so that we have received all the debug info
1416+
// from the server by the time we emit it.
1417+
forwardDebugInfo(request, debugID, debugInfo);
1418+
}
1419+
}
1420+
}
1421+
13811422
if (task.keyPath !== null) {
13821423
// We have a Server Component that specifies a key but we're now splitting
13831424
// the tree using a fragment.
@@ -1969,7 +2010,23 @@ if (__DEV__) {
19692010
_writtenObjects.set(value, -1);
19702011
}
19712012

1972-
var element = value; // Attempt to render the Server Component.
2013+
var element = value;
2014+
2015+
{
2016+
var debugInfo = value._debugInfo;
2017+
2018+
if (debugInfo) {
2019+
// If this came from Flight, forward any debug info into this new row.
2020+
if (debugID === null) {
2021+
// We don't have a chunk to assign debug info. We need to outline this
2022+
// component to assign it an ID.
2023+
return outlineTask(request, task);
2024+
} else {
2025+
// Forward any debug info we have the first time we see it.
2026+
forwardDebugInfo(request, debugID, debugInfo);
2027+
}
2028+
}
2029+
} // Attempt to render the Server Component.
19732030

19742031
return renderElement(
19752032
request,
@@ -1982,9 +2039,32 @@ if (__DEV__) {
19822039
}
19832040

19842041
case REACT_LAZY_TYPE: {
1985-
var payload = value._payload;
1986-
var init = value._init;
2042+
// Reset the task's thenable state before continuing. If there was one, it was
2043+
// from suspending the lazy before.
2044+
task.thenableState = null;
2045+
var lazy = value;
2046+
var payload = lazy._payload;
2047+
var init = lazy._init;
19872048
var resolvedModel = init(payload);
2049+
2050+
{
2051+
var _debugInfo = lazy._debugInfo;
2052+
2053+
if (_debugInfo) {
2054+
// If this came from Flight, forward any debug info into this new row.
2055+
if (debugID === null) {
2056+
// We don't have a chunk to assign debug info. We need to outline this
2057+
// component to assign it an ID.
2058+
return outlineTask(request, task);
2059+
} else {
2060+
// Forward any debug info we have the first time we see it.
2061+
// We do this after init so that we have received all the debug info
2062+
// from the server by the time we emit it.
2063+
forwardDebugInfo(request, debugID, _debugInfo);
2064+
}
2065+
}
2066+
}
2067+
19882068
return renderModelDestructive(
19892069
request,
19902070
task,
@@ -2310,6 +2390,13 @@ if (__DEV__) {
23102390
request.completedRegularChunks.push(processedChunk);
23112391
}
23122392

2393+
function forwardDebugInfo(request, id, debugInfo) {
2394+
for (var i = 0; i < debugInfo.length; i++) {
2395+
request.pendingChunks++;
2396+
emitDebugChunk(request, id, debugInfo[i]);
2397+
}
2398+
}
2399+
23132400
var emptyRoot = {};
23142401

23152402
function retryTask(request, task) {
@@ -2578,7 +2665,9 @@ if (__DEV__) {
25782665
var request = createRequest(
25792666
model,
25802667
null,
2581-
options ? options.onError : undefined
2668+
options ? options.onError : undefined,
2669+
undefined,
2670+
undefined
25822671
);
25832672
startWork(request);
25842673
startFlowing(request, destination);

compiled/facebook-www/ReactFlightDOMServer-prod.modern.js

+1
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ function renderModelDestructive(
797797
);
798798
case REACT_LAZY_TYPE:
799799
return (
800+
(task.thenableState = null),
800801
(parent = value._init),
801802
(value = parent(value._payload)),
802803
renderModelDestructive(request, task, emptyRoot, "", value)

compiled/facebook-www/ReactTestRenderer-dev.modern.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26096,7 +26096,7 @@ if (__DEV__) {
2609626096
return root;
2609726097
}
2609826098

26099-
var ReactVersion = "18.3.0-www-modern-623a68d9";
26099+
var ReactVersion = "18.3.0-www-modern-f687cbe4";
2610026100

2610126101
// Might add PROFILE later.
2610226102

0 commit comments

Comments
 (0)